Config.java revision 8d536f3db19e8ea7426e98e470dc15d10ecbae87
1ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu/*
2ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * Copyright (C) 2012 The Android Open Source Project
3ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu *
4ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * Licensed under the Apache License, Version 2.0 (the "License");
5ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * you may not use this file except in compliance with the License.
6ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * You may obtain a copy of the License at
7ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu *
8ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu *      http://www.apache.org/licenses/LICENSE-2.0
9ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu *
10ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * Unless required by applicable law or agreed to in writing, software
11ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * distributed under the License is distributed on an "AS IS" BASIS,
12ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * See the License for the specific language governing permissions and
14ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu * limitations under the License.
15ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu */
16ede67c26e7b2564ea35db6d9b3027a269c150e13Zhihai Xu
17a7e8ef3f77ac74449f817f36f570a3545285be85fredcpackage com.android.bluetooth.btservice;
18a7e8ef3f77ac74449f817f36f570a3545285be85fredc
19a7e8ef3f77ac74449f817f36f570a3545285be85fredcimport java.util.ArrayList;
20a7e8ef3f77ac74449f817f36f570a3545285be85fredc
21a7e8ef3f77ac74449f817f36f570a3545285be85fredcimport android.content.Context;
22a7e8ef3f77ac74449f817f36f570a3545285be85fredcimport android.content.res.Resources;
23aebc726105204f8a7b977eb3556c14b5ba18a5caHemant Guptaimport android.os.SystemProperties;
24a7e8ef3f77ac74449f817f36f570a3545285be85fredcimport android.util.Log;
25a7e8ef3f77ac74449f817f36f570a3545285be85fredc
26a7e8ef3f77ac74449f817f36f570a3545285be85fredcimport com.android.bluetooth.R;
27a7e8ef3f77ac74449f817f36f570a3545285be85fredcimport com.android.bluetooth.a2dp.A2dpService;
28a7e8ef3f77ac74449f817f36f570a3545285be85fredcimport com.android.bluetooth.hdp.HealthService;
29a7e8ef3f77ac74449f817f36f570a3545285be85fredcimport com.android.bluetooth.hfp.HeadsetService;
308d536f3db19e8ea7426e98e470dc15d10ecbae87Mike Lockwoodimport com.android.bluetooth.hfpclient.HeadsetClientService;
31a7e8ef3f77ac74449f817f36f570a3545285be85fredcimport com.android.bluetooth.hid.HidService;
32a7e8ef3f77ac74449f817f36f570a3545285be85fredcimport com.android.bluetooth.pan.PanService;
3303b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Battaimport com.android.bluetooth.gatt.GattService;
3470be005a18a35ec5fcb46152f0dfbe82156efa3aKim Schulzimport com.android.bluetooth.map.BluetoothMapService;
35a7e8ef3f77ac74449f817f36f570a3545285be85fredc
36a7e8ef3f77ac74449f817f36f570a3545285be85fredcpublic class Config {
37a7e8ef3f77ac74449f817f36f570a3545285be85fredc    private static final String TAG = "AdapterServiceConfig";
38a7e8ef3f77ac74449f817f36f570a3545285be85fredc    /**
39a7e8ef3f77ac74449f817f36f570a3545285be85fredc     * List of profile services.
40a7e8ef3f77ac74449f817f36f570a3545285be85fredc     */
41a7e8ef3f77ac74449f817f36f570a3545285be85fredc    @SuppressWarnings("rawtypes")
42a7e8ef3f77ac74449f817f36f570a3545285be85fredc    //Do not inclue OPP and PBAP, because their services
43a7e8ef3f77ac74449f817f36f570a3545285be85fredc    //are not managed by AdapterService
44a7e8ef3f77ac74449f817f36f570a3545285be85fredc    private static final Class[] PROFILE_SERVICES = {
45a7e8ef3f77ac74449f817f36f570a3545285be85fredc        HeadsetService.class,
46a7e8ef3f77ac74449f817f36f570a3545285be85fredc        A2dpService.class,
47a7e8ef3f77ac74449f817f36f570a3545285be85fredc        HidService.class,
48a7e8ef3f77ac74449f817f36f570a3545285be85fredc        HealthService.class,
4903b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta        PanService.class,
5070be005a18a35ec5fcb46152f0dfbe82156efa3aKim Schulz        GattService.class,
51aebc726105204f8a7b977eb3556c14b5ba18a5caHemant Gupta        BluetoothMapService.class,
528d536f3db19e8ea7426e98e470dc15d10ecbae87Mike Lockwood        HeadsetClientService.class,
53a7e8ef3f77ac74449f817f36f570a3545285be85fredc    };
54a7e8ef3f77ac74449f817f36f570a3545285be85fredc    /**
55a7e8ef3f77ac74449f817f36f570a3545285be85fredc     * Resource flag to indicate whether profile is supported or not.
56a7e8ef3f77ac74449f817f36f570a3545285be85fredc     */
57a7e8ef3f77ac74449f817f36f570a3545285be85fredc    private static final int[]  PROFILE_SERVICES_FLAG = {
58a7e8ef3f77ac74449f817f36f570a3545285be85fredc        R.bool.profile_supported_hs_hfp,
59a7e8ef3f77ac74449f817f36f570a3545285be85fredc        R.bool.profile_supported_a2dp,
60a7e8ef3f77ac74449f817f36f570a3545285be85fredc        R.bool.profile_supported_hid,
61a7e8ef3f77ac74449f817f36f570a3545285be85fredc        R.bool.profile_supported_hdp,
6203b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta        R.bool.profile_supported_pan,
6370be005a18a35ec5fcb46152f0dfbe82156efa3aKim Schulz        R.bool.profile_supported_gatt,
64aebc726105204f8a7b977eb3556c14b5ba18a5caHemant Gupta        R.bool.profile_supported_map,
65aebc726105204f8a7b977eb3556c14b5ba18a5caHemant Gupta        R.bool.profile_supported_hfpclient
66a7e8ef3f77ac74449f817f36f570a3545285be85fredc    };
67a7e8ef3f77ac74449f817f36f570a3545285be85fredc
68a7e8ef3f77ac74449f817f36f570a3545285be85fredc    private static Class[] SUPPORTED_PROFILES = new Class[0];
69a7e8ef3f77ac74449f817f36f570a3545285be85fredc
70a7e8ef3f77ac74449f817f36f570a3545285be85fredc    static void init(Context ctx) {
71a7e8ef3f77ac74449f817f36f570a3545285be85fredc        if (ctx == null) {
72a7e8ef3f77ac74449f817f36f570a3545285be85fredc            return;
73a7e8ef3f77ac74449f817f36f570a3545285be85fredc        }
74a7e8ef3f77ac74449f817f36f570a3545285be85fredc        Resources resources = ctx.getResources();
75a7e8ef3f77ac74449f817f36f570a3545285be85fredc        if (resources == null) {
76a7e8ef3f77ac74449f817f36f570a3545285be85fredc            return;
77a7e8ef3f77ac74449f817f36f570a3545285be85fredc        }
78a7e8ef3f77ac74449f817f36f570a3545285be85fredc        ArrayList<Class> profiles = new ArrayList<Class>(PROFILE_SERVICES.length);
79a7e8ef3f77ac74449f817f36f570a3545285be85fredc        for (int i=0; i < PROFILE_SERVICES_FLAG.length; i++) {
80a7e8ef3f77ac74449f817f36f570a3545285be85fredc            boolean supported = resources.getBoolean(PROFILE_SERVICES_FLAG[i]);
81a7e8ef3f77ac74449f817f36f570a3545285be85fredc            if (supported) {
82a7e8ef3f77ac74449f817f36f570a3545285be85fredc                Log.d(TAG, "Adding " + PROFILE_SERVICES[i].getSimpleName());
83a7e8ef3f77ac74449f817f36f570a3545285be85fredc                profiles.add(PROFILE_SERVICES[i]);
84a7e8ef3f77ac74449f817f36f570a3545285be85fredc            }
85a7e8ef3f77ac74449f817f36f570a3545285be85fredc        }
86a7e8ef3f77ac74449f817f36f570a3545285be85fredc        int totalProfiles = profiles.size();
87a7e8ef3f77ac74449f817f36f570a3545285be85fredc        SUPPORTED_PROFILES = new Class[totalProfiles];
88a7e8ef3f77ac74449f817f36f570a3545285be85fredc        profiles.toArray(SUPPORTED_PROFILES);
89a7e8ef3f77ac74449f817f36f570a3545285be85fredc    }
90a7e8ef3f77ac74449f817f36f570a3545285be85fredc
91a7e8ef3f77ac74449f817f36f570a3545285be85fredc    static Class[]  getSupportedProfiles() {
92a7e8ef3f77ac74449f817f36f570a3545285be85fredc        return SUPPORTED_PROFILES;
93a7e8ef3f77ac74449f817f36f570a3545285be85fredc    }
94a7e8ef3f77ac74449f817f36f570a3545285be85fredc}
95