1 /* 2 * Copyright (C) 2022 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.server.companion.utils; 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_VIRTUAL_DEVICE; 25 import static android.companion.AssociationRequest.DEVICE_PROFILE_WATCH; 26 import static android.companion.AssociationRequest.DEVICE_PROFILE_WEARABLE_SENSING; 27 28 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION; 29 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__ACTION__CREATED; 30 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__ACTION__REMOVED; 31 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_APP_STREAMING; 32 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_AUTO_PROJECTION; 33 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_COMPUTER; 34 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_GLASSES; 35 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_NEARBY_DEVICE_STREAMING; 36 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_NULL; 37 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_VIRTUAL_DEVICE; 38 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_WATCH; 39 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_WEARABLE_SENSING; 40 import static com.android.internal.util.FrameworkStatsLog.write; 41 42 import static java.util.Collections.unmodifiableMap; 43 44 import android.util.ArrayMap; 45 46 import java.util.Map; 47 48 public final class MetricUtils { 49 50 private static final Map<String, Integer> METRIC_DEVICE_PROFILE; 51 static { 52 final Map<String, Integer> map = new ArrayMap<>(); map.put(null, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_NULL)53 map.put(null, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_NULL); map.put( DEVICE_PROFILE_WATCH, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_WATCH )54 map.put( 55 DEVICE_PROFILE_WATCH, 56 CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_WATCH 57 ); map.put( DEVICE_PROFILE_APP_STREAMING, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_APP_STREAMING )58 map.put( 59 DEVICE_PROFILE_APP_STREAMING, 60 CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_APP_STREAMING 61 ); map.put( DEVICE_PROFILE_AUTOMOTIVE_PROJECTION, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_AUTO_PROJECTION )62 map.put( 63 DEVICE_PROFILE_AUTOMOTIVE_PROJECTION, 64 CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_AUTO_PROJECTION 65 ); map.put( DEVICE_PROFILE_COMPUTER, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_COMPUTER )66 map.put( 67 DEVICE_PROFILE_COMPUTER, 68 CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_COMPUTER 69 ); map.put( DEVICE_PROFILE_GLASSES, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_GLASSES )70 map.put( 71 DEVICE_PROFILE_GLASSES, 72 CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_GLASSES 73 ); map.put( DEVICE_PROFILE_NEARBY_DEVICE_STREAMING, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_NEARBY_DEVICE_STREAMING )74 map.put( 75 DEVICE_PROFILE_NEARBY_DEVICE_STREAMING, 76 CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_NEARBY_DEVICE_STREAMING 77 ); map.put( DEVICE_PROFILE_VIRTUAL_DEVICE, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_VIRTUAL_DEVICE )78 map.put( 79 DEVICE_PROFILE_VIRTUAL_DEVICE, 80 CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_VIRTUAL_DEVICE 81 ); map.put( DEVICE_PROFILE_WEARABLE_SENSING, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_WEARABLE_SENSING )82 map.put( 83 DEVICE_PROFILE_WEARABLE_SENSING, 84 CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_WEARABLE_SENSING 85 ); 86 87 METRIC_DEVICE_PROFILE = unmodifiableMap(map); 88 } 89 90 /** 91 * Log association creation 92 */ logCreateAssociation(String profile)93 public static void logCreateAssociation(String profile) { 94 write(CDM_ASSOCIATION_ACTION, 95 CDM_ASSOCIATION_ACTION__ACTION__CREATED, 96 METRIC_DEVICE_PROFILE.get(profile)); 97 } 98 99 /** 100 * Log association removal 101 */ logRemoveAssociation(String profile)102 public static void logRemoveAssociation(String profile) { 103 write(CDM_ASSOCIATION_ACTION, 104 CDM_ASSOCIATION_ACTION__ACTION__REMOVED, 105 METRIC_DEVICE_PROFILE.get(profile)); 106 } 107 } 108