Config.java revision a7e8ef3f77ac74449f817f36f570a3545285be85
1package com.android.bluetooth.btservice;
2
3import java.util.ArrayList;
4
5import android.content.Context;
6import android.content.res.Resources;
7import android.util.Log;
8
9import com.android.bluetooth.R;
10import com.android.bluetooth.a2dp.A2dpService;
11import com.android.bluetooth.hdp.HealthService;
12import com.android.bluetooth.hfp.HeadsetService;
13import com.android.bluetooth.hid.HidService;
14import com.android.bluetooth.pan.PanService;
15
16public class Config {
17    private static final String TAG = "AdapterServiceConfig";
18    /**
19     * List of profile services.
20     */
21    @SuppressWarnings("rawtypes")
22    //Do not inclue OPP and PBAP, because their services
23    //are not managed by AdapterService
24    private static final Class[] PROFILE_SERVICES = {
25        HeadsetService.class,
26        A2dpService.class,
27        HidService.class,
28        HealthService.class,
29        PanService.class
30    };
31    /**
32     * Resource flag to indicate whether profile is supported or not.
33     */
34    private static final int[]  PROFILE_SERVICES_FLAG = {
35        R.bool.profile_supported_hs_hfp,
36        R.bool.profile_supported_a2dp,
37        R.bool.profile_supported_hid,
38        R.bool.profile_supported_hdp,
39        R.bool.profile_supported_pan
40    };
41
42    private static Class[] SUPPORTED_PROFILES = new Class[0];
43
44    static void init(Context ctx) {
45        if (ctx == null) {
46            return;
47        }
48        Resources resources = ctx.getResources();
49        if (resources == null) {
50            return;
51        }
52        ArrayList<Class> profiles = new ArrayList<Class>(PROFILE_SERVICES.length);
53        for (int i=0; i < PROFILE_SERVICES_FLAG.length; i++) {
54            boolean supported = resources.getBoolean(PROFILE_SERVICES_FLAG[i]);
55            if (supported) {
56                Log.d(TAG, "Adding " + PROFILE_SERVICES[i].getSimpleName());
57                profiles.add(PROFILE_SERVICES[i]);
58            }
59        }
60        int totalProfiles = profiles.size();
61        SUPPORTED_PROFILES = new Class[totalProfiles];
62        profiles.toArray(SUPPORTED_PROFILES);
63    }
64
65    static Class[]  getSupportedProfiles() {
66        return SUPPORTED_PROFILES;
67    }
68}
69