• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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.bluetooth.btservice;
18 
19 import java.util.ArrayList;
20 
21 import android.content.Context;
22 import android.content.res.Resources;
23 import android.util.Log;
24 
25 import com.android.bluetooth.R;
26 import com.android.bluetooth.a2dp.A2dpService;
27 import com.android.bluetooth.hdp.HealthService;
28 import com.android.bluetooth.hfp.HeadsetService;
29 import com.android.bluetooth.hid.HidService;
30 import com.android.bluetooth.pan.PanService;
31 import com.android.bluetooth.gatt.GattService;
32 
33 public class Config {
34     private static final String TAG = "AdapterServiceConfig";
35     /**
36      * List of profile services.
37      */
38     @SuppressWarnings("rawtypes")
39     //Do not inclue OPP and PBAP, because their services
40     //are not managed by AdapterService
41     private static final Class[] PROFILE_SERVICES = {
42         HeadsetService.class,
43         A2dpService.class,
44         HidService.class,
45         HealthService.class,
46         PanService.class,
47         GattService.class
48     };
49     /**
50      * Resource flag to indicate whether profile is supported or not.
51      */
52     private static final int[]  PROFILE_SERVICES_FLAG = {
53         R.bool.profile_supported_hs_hfp,
54         R.bool.profile_supported_a2dp,
55         R.bool.profile_supported_hid,
56         R.bool.profile_supported_hdp,
57         R.bool.profile_supported_pan,
58         R.bool.profile_supported_gatt
59     };
60 
61     private static Class[] SUPPORTED_PROFILES = new Class[0];
62 
init(Context ctx)63     static void init(Context ctx) {
64         if (ctx == null) {
65             return;
66         }
67         Resources resources = ctx.getResources();
68         if (resources == null) {
69             return;
70         }
71         ArrayList<Class> profiles = new ArrayList<Class>(PROFILE_SERVICES.length);
72         for (int i=0; i < PROFILE_SERVICES_FLAG.length; i++) {
73             boolean supported = resources.getBoolean(PROFILE_SERVICES_FLAG[i]);
74             if (supported) {
75                 Log.d(TAG, "Adding " + PROFILE_SERVICES[i].getSimpleName());
76                 profiles.add(PROFILE_SERVICES[i]);
77             }
78         }
79         int totalProfiles = profiles.size();
80         SUPPORTED_PROFILES = new Class[totalProfiles];
81         profiles.toArray(SUPPORTED_PROFILES);
82     }
83 
getSupportedProfiles()84     static Class[]  getSupportedProfiles() {
85         return SUPPORTED_PROFILES;
86     }
87 }
88