1 /*
2  * Copyright (C) 2024 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 package com.android.bluetooth.pbap;
17 
18 import android.bluetooth.BluetoothProfile;
19 import android.bluetooth.BluetoothProtoEnums;
20 import android.content.Context;
21 import android.content.res.Resources;
22 import android.util.Log;
23 
24 import com.android.bluetooth.BluetoothStatsLog;
25 import com.android.bluetooth.R;
26 import com.android.bluetooth.content_profiles.ContentProfileErrorReportUtils;
27 import com.android.internal.annotations.VisibleForTesting;
28 
29 // Next tag value for ContentProfileErrorReportUtils.report(): 2
30 public class BluetoothPbapConfig {
31     private static boolean sUseProfileForOwnerVcard = true;
32     private static boolean sIncludePhotosInVcard = false;
33 
init(Context ctx)34     public static void init(Context ctx) {
35         Resources r = ctx.getResources();
36         if (r != null) {
37             try {
38                 sUseProfileForOwnerVcard = r.getBoolean(R.bool.pbap_use_profile_for_owner_vcard);
39             } catch (Exception e) {
40                 ContentProfileErrorReportUtils.report(
41                         BluetoothProfile.PBAP,
42                         BluetoothProtoEnums.BLUETOOTH_PBAP_CONFIG,
43                         BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
44                         0);
45 
46                 Log.e("BluetoothPbapConfig", "", e);
47             }
48             try {
49                 sIncludePhotosInVcard = r.getBoolean(R.bool.pbap_include_photos_in_vcard);
50             } catch (Exception e) {
51                 ContentProfileErrorReportUtils.report(
52                         BluetoothProfile.PBAP,
53                         BluetoothProtoEnums.BLUETOOTH_PBAP_CONFIG,
54                         BluetoothStatsLog.BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__EXCEPTION,
55                         1);
56                 Log.e("BluetoothPbapConfig", "", e);
57             }
58         }
59     }
60 
61     /** If true, owner vcard will be generated from the "Me" profile */
useProfileForOwnerVcard()62     public static boolean useProfileForOwnerVcard() {
63         return sUseProfileForOwnerVcard;
64     }
65 
66     /** If true, include photos in contact information returned to PCE */
includePhotosInVcard()67     public static boolean includePhotosInVcard() {
68         return sIncludePhotosInVcard;
69     }
70 
71     @VisibleForTesting
setIncludePhotosInVcard(boolean includePhotosInVcard)72     public static void setIncludePhotosInVcard(boolean includePhotosInVcard) {
73         sIncludePhotosInVcard = includePhotosInVcard;
74     }
75 }
76