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