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