• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
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_WATCH;
23 
24 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION;
25 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__ACTION__CREATED;
26 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__ACTION__REMOVED;
27 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_APP_STREAMING;
28 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_AUTO_PROJECTION;
29 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_COMPUTER;
30 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_NULL;
31 import static com.android.internal.util.FrameworkStatsLog.CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_WATCH;
32 import static com.android.internal.util.FrameworkStatsLog.write;
33 
34 import static java.util.Collections.unmodifiableMap;
35 
36 import android.util.ArrayMap;
37 
38 import java.util.Map;
39 
40 final class MetricUtils {
41 
42     private static final Map<String, Integer> METRIC_DEVICE_PROFILE;
43     static {
44         final Map<String, Integer> map = new ArrayMap<>();
map.put(null, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_NULL)45         map.put(null, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_NULL);
map.put( DEVICE_PROFILE_WATCH, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_WATCH )46         map.put(
47                 DEVICE_PROFILE_WATCH,
48                 CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_WATCH
49         );
map.put( DEVICE_PROFILE_APP_STREAMING, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_APP_STREAMING )50         map.put(
51                 DEVICE_PROFILE_APP_STREAMING,
52                 CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_APP_STREAMING
53         );
map.put( DEVICE_PROFILE_AUTOMOTIVE_PROJECTION, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_AUTO_PROJECTION )54         map.put(
55                 DEVICE_PROFILE_AUTOMOTIVE_PROJECTION,
56                 CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_AUTO_PROJECTION
57         );
map.put( DEVICE_PROFILE_COMPUTER, CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_COMPUTER )58         map.put(
59                 DEVICE_PROFILE_COMPUTER,
60                 CDM_ASSOCIATION_ACTION__DEVICE_PROFILE__DEVICE_PROFILE_COMPUTER
61         );
62 
63         METRIC_DEVICE_PROFILE = unmodifiableMap(map);
64     }
65 
logCreateAssociation(String profile)66     static void logCreateAssociation(String profile) {
67         write(CDM_ASSOCIATION_ACTION,
68                 CDM_ASSOCIATION_ACTION__ACTION__CREATED,
69                 METRIC_DEVICE_PROFILE.get(profile));
70     }
71 
logRemoveAssociation(String profile)72     static void logRemoveAssociation(String profile) {
73         write(CDM_ASSOCIATION_ACTION,
74                 CDM_ASSOCIATION_ACTION__ACTION__REMOVED,
75                 METRIC_DEVICE_PROFILE.get(profile));
76     }
77 }
78