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