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