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