Loading android/app/AndroidManifest.xml +9 −0 Original line number Diff line number Diff line Loading @@ -367,6 +367,15 @@ </intent-filter> </service> <service android:process="@string/process" android:name=".mcp.McpService" android:exported="true" android:enabled="@bool/profile_supported_mcp_server"> <intent-filter> <action android:name="android.bluetooth.IBluetoothMcpService" /> </intent-filter> </service> <service android:process="@string/process" android:name=".pan.PanService" android:enabled="@bool/profile_supported_pan" android:exported="true"> Loading android/app/res/values/config.xml +1 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ <bool name="profile_supported_mapmce">false</bool> <bool name="profile_supported_hid_device">true</bool> <bool name="profile_supported_vc">false</bool> <bool name="profile_supported_mcp_server">true</bool> <!-- If true, we will require location to be enabled on the device to fire Bluetooth LE scan result callbacks in addition to having one Loading android/app/src/com/android/bluetooth/btservice/Config.java +3 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import com.android.bluetooth.hid.HidDeviceService; import com.android.bluetooth.hid.HidHostService; import com.android.bluetooth.map.BluetoothMapService; import com.android.bluetooth.mapclient.MapClientService; import com.android.bluetooth.mcp.McpService; import com.android.bluetooth.opp.BluetoothOppService; import com.android.bluetooth.pan.PanService; import com.android.bluetooth.pbap.BluetoothPbapService; Loading Loading @@ -107,6 +108,8 @@ public class Config { (1 << BluetoothProfile.PBAP)), new ProfileConfig(VolumeControlService.class, R.bool.profile_supported_vc, (1 << BluetoothProfile.VOLUME_CONTROL)), new ProfileConfig(McpService.class, R.bool.profile_supported_mcp_server, (1 << BluetoothProfile.MCP_SERVER)), new ProfileConfig(HearingAidService.class, com.android.internal.R.bool.config_hearing_aid_profile_supported, (1 << BluetoothProfile.HEARING_AID)) Loading android/app/src/com/android/bluetooth/btservice/ServiceFactory.java +5 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import com.android.bluetooth.hearingaid.HearingAidService; import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.hid.HidDeviceService; import com.android.bluetooth.hid.HidHostService; import com.android.bluetooth.mcp.McpService; import com.android.bluetooth.pan.PanService; // Factory class to create instances of static services. Useful in mocking the service objects. Loading Loading @@ -53,4 +54,8 @@ public class ServiceFactory { public AvrcpTargetService getAvrcpTargetService() { return AvrcpTargetService.get(); } public McpService getMcpService() { return McpService.getMcpService(); } } android/app/src/com/android/bluetooth/mcp/McpService.java 0 → 100644 +154 −0 Original line number Diff line number Diff line /* * Copyright 2021 HIMSA II K/S - www.himsa.com. * Represented by EHIMA - www.ehima.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.bluetooth.mcp; import android.bluetooth.BluetoothDevice; import android.bluetooth.IBluetoothMcpServiceManager; import android.util.Log; import com.android.bluetooth.Utils; import com.android.bluetooth.btservice.ProfileService; /** * Provides Media Control Profile, as a service in the Bluetooth application. * @hide */ public class McpService extends ProfileService { private static final boolean DBG = true; private static final boolean VDBG = false; private static final String TAG = "McpService"; private static McpService sMcpService; private static synchronized void setMcpService(McpService instance) { if (VDBG) { Log.d(TAG, "setMcpService(): set to: " + instance); } sMcpService = instance; } public static synchronized McpService getMcpService() { if (sMcpService == null) { Log.w(TAG, "getMcpService(): service is NULL"); return null; } if (!sMcpService.isAvailable()) { Log.w(TAG, "getMcpService(): service is not available"); return null; } return sMcpService; } @Override protected IProfileServiceBinder initBinder() { return new BluetoothMcpServiceBinder(this); } @Override protected void create() { if (DBG) { Log.d(TAG, "create()"); } } @Override protected boolean start() { if (DBG) { Log.d(TAG, "start()"); } if (sMcpService != null) { throw new IllegalStateException("start() called twice"); } // Mark service as started setMcpService(this); return true; } @Override protected boolean stop() { if (DBG) { Log.d(TAG, "stop()"); } if (sMcpService == null) { Log.w(TAG, "stop() called before start()"); return true; } // Mark service as stopped setMcpService(null); return true; } @Override protected void cleanup() { if (DBG) { Log.d(TAG, "cleanup()"); } } void setDeviceAuthorized(BluetoothDevice device, boolean isAuthorized) { } /** * Binder object: must be a static class or memory leak may occur */ static class BluetoothMcpServiceBinder extends IBluetoothMcpServiceManager.Stub implements IProfileServiceBinder { private McpService mService; BluetoothMcpServiceBinder(McpService svc) { mService = svc; } private McpService getService() { if (mService != null && mService.isAvailable()) { return mService; } Log.e(TAG, "getService() - Service requested, but not available!"); return null; } @Override public void setDeviceAuthorized(BluetoothDevice device, boolean isAuthorized) { McpService service = getService(); if (service == null) { return; } service.enforceCallingOrSelfPermission( BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); service.setDeviceAuthorized(device, isAuthorized); } @Override public void cleanup() { mService = null; } } @Override public void dump(StringBuilder sb) { super.dump(sb); } } Loading
android/app/AndroidManifest.xml +9 −0 Original line number Diff line number Diff line Loading @@ -367,6 +367,15 @@ </intent-filter> </service> <service android:process="@string/process" android:name=".mcp.McpService" android:exported="true" android:enabled="@bool/profile_supported_mcp_server"> <intent-filter> <action android:name="android.bluetooth.IBluetoothMcpService" /> </intent-filter> </service> <service android:process="@string/process" android:name=".pan.PanService" android:enabled="@bool/profile_supported_pan" android:exported="true"> Loading
android/app/res/values/config.xml +1 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ <bool name="profile_supported_mapmce">false</bool> <bool name="profile_supported_hid_device">true</bool> <bool name="profile_supported_vc">false</bool> <bool name="profile_supported_mcp_server">true</bool> <!-- If true, we will require location to be enabled on the device to fire Bluetooth LE scan result callbacks in addition to having one Loading
android/app/src/com/android/bluetooth/btservice/Config.java +3 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import com.android.bluetooth.hid.HidDeviceService; import com.android.bluetooth.hid.HidHostService; import com.android.bluetooth.map.BluetoothMapService; import com.android.bluetooth.mapclient.MapClientService; import com.android.bluetooth.mcp.McpService; import com.android.bluetooth.opp.BluetoothOppService; import com.android.bluetooth.pan.PanService; import com.android.bluetooth.pbap.BluetoothPbapService; Loading Loading @@ -107,6 +108,8 @@ public class Config { (1 << BluetoothProfile.PBAP)), new ProfileConfig(VolumeControlService.class, R.bool.profile_supported_vc, (1 << BluetoothProfile.VOLUME_CONTROL)), new ProfileConfig(McpService.class, R.bool.profile_supported_mcp_server, (1 << BluetoothProfile.MCP_SERVER)), new ProfileConfig(HearingAidService.class, com.android.internal.R.bool.config_hearing_aid_profile_supported, (1 << BluetoothProfile.HEARING_AID)) Loading
android/app/src/com/android/bluetooth/btservice/ServiceFactory.java +5 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import com.android.bluetooth.hearingaid.HearingAidService; import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.hid.HidDeviceService; import com.android.bluetooth.hid.HidHostService; import com.android.bluetooth.mcp.McpService; import com.android.bluetooth.pan.PanService; // Factory class to create instances of static services. Useful in mocking the service objects. Loading Loading @@ -53,4 +54,8 @@ public class ServiceFactory { public AvrcpTargetService getAvrcpTargetService() { return AvrcpTargetService.get(); } public McpService getMcpService() { return McpService.getMcpService(); } }
android/app/src/com/android/bluetooth/mcp/McpService.java 0 → 100644 +154 −0 Original line number Diff line number Diff line /* * Copyright 2021 HIMSA II K/S - www.himsa.com. * Represented by EHIMA - www.ehima.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.bluetooth.mcp; import android.bluetooth.BluetoothDevice; import android.bluetooth.IBluetoothMcpServiceManager; import android.util.Log; import com.android.bluetooth.Utils; import com.android.bluetooth.btservice.ProfileService; /** * Provides Media Control Profile, as a service in the Bluetooth application. * @hide */ public class McpService extends ProfileService { private static final boolean DBG = true; private static final boolean VDBG = false; private static final String TAG = "McpService"; private static McpService sMcpService; private static synchronized void setMcpService(McpService instance) { if (VDBG) { Log.d(TAG, "setMcpService(): set to: " + instance); } sMcpService = instance; } public static synchronized McpService getMcpService() { if (sMcpService == null) { Log.w(TAG, "getMcpService(): service is NULL"); return null; } if (!sMcpService.isAvailable()) { Log.w(TAG, "getMcpService(): service is not available"); return null; } return sMcpService; } @Override protected IProfileServiceBinder initBinder() { return new BluetoothMcpServiceBinder(this); } @Override protected void create() { if (DBG) { Log.d(TAG, "create()"); } } @Override protected boolean start() { if (DBG) { Log.d(TAG, "start()"); } if (sMcpService != null) { throw new IllegalStateException("start() called twice"); } // Mark service as started setMcpService(this); return true; } @Override protected boolean stop() { if (DBG) { Log.d(TAG, "stop()"); } if (sMcpService == null) { Log.w(TAG, "stop() called before start()"); return true; } // Mark service as stopped setMcpService(null); return true; } @Override protected void cleanup() { if (DBG) { Log.d(TAG, "cleanup()"); } } void setDeviceAuthorized(BluetoothDevice device, boolean isAuthorized) { } /** * Binder object: must be a static class or memory leak may occur */ static class BluetoothMcpServiceBinder extends IBluetoothMcpServiceManager.Stub implements IProfileServiceBinder { private McpService mService; BluetoothMcpServiceBinder(McpService svc) { mService = svc; } private McpService getService() { if (mService != null && mService.isAvailable()) { return mService; } Log.e(TAG, "getService() - Service requested, but not available!"); return null; } @Override public void setDeviceAuthorized(BluetoothDevice device, boolean isAuthorized) { McpService service = getService(); if (service == null) { return; } service.enforceCallingOrSelfPermission( BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission"); service.setDeviceAuthorized(device, isAuthorized); } @Override public void cleanup() { mService = null; } } @Override public void dump(StringBuilder sb) { super.dump(sb); } }