Loading android/app/src/com/android/bluetooth/tbs/TbsGeneric.java +60 −8 Original line number Diff line number Diff line Loading @@ -18,15 +18,14 @@ package com.android.bluetooth.tbs; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattDescriptor; import android.bluetooth.BluetoothGattServerCallback; import android.bluetooth.BluetoothGattService; import android.bluetooth.BluetoothLeCallControl; import android.bluetooth.BluetoothLeCall; import android.bluetooth.BluetoothLeCallControl; import android.bluetooth.IBluetoothLeCallControlCallback; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.media.AudioManager; import android.net.Uri; import android.os.ParcelUuid; import android.os.RemoteException; Loading Loading @@ -115,6 +114,28 @@ public class TbsGeneric { private Bearer mForegroundBearer = null; private int mLastRequestIdAssigned = 0; private List<String> mUriSchemes = new ArrayList<>(Arrays.asList("tel")); private Receiver mReceiver = null; private int mStoredRingerMode = -1; private final class Receiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { int ringerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1); if (ringerMode < 0 || ringerMode == mStoredRingerMode) return; mStoredRingerMode = ringerMode; if (isSilentModeEnabled()) { mTbsGatt.setSilentModeFlag(); } else { mTbsGatt.clearSilentModeFlag(); } } } }; public boolean init(TbsGatt tbsGatt) { if (DBG) { Loading @@ -128,8 +149,32 @@ public class TbsGeneric { return false; } return mTbsGatt.init(ccid, UCI, mUriSchemes, true, true, DEFAULT_PROVIDER_NAME, DEFAULT_BEARER_TECHNOLOGY, mTbsGattCallback); if (!mTbsGatt.init(ccid, UCI, mUriSchemes, true, true, DEFAULT_PROVIDER_NAME, DEFAULT_BEARER_TECHNOLOGY, mTbsGattCallback)) { Log.e(TAG, " TbsGatt init failed"); return false; } AudioManager mAudioManager = mTbsGatt.getContext() .getSystemService(AudioManager.class); if (mAudioManager == null) { Log.w(TAG, " AudioManager is not available"); return true; } // read initial value of ringer mode mStoredRingerMode = mAudioManager.getRingerMode(); if (isSilentModeEnabled()) { mTbsGatt.setSilentModeFlag(); } else { mTbsGatt.clearSilentModeFlag(); } mReceiver = new Receiver(); mTbsGatt.getContext().registerReceiver(mReceiver, new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION)); return true; } public void cleanup() { Loading @@ -138,11 +183,18 @@ public class TbsGeneric { } if (mTbsGatt != null) { if (mReceiver != null) { mTbsGatt.getContext().unregisterReceiver(mReceiver); } mTbsGatt.cleanup(); mTbsGatt = null; } } private boolean isSilentModeEnabled() { return mStoredRingerMode != AudioManager.RINGER_MODE_NORMAL; } private Bearer getBearerByToken(String token) { synchronized (mBearerList) { for (Bearer bearer : mBearerList) { Loading android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGenericTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import androidx.test.InstrumentationRegistry; import androidx.test.filters.MediumTest; import androidx.test.rule.ServiceTestRule; import androidx.test.runner.AndroidJUnit4; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import com.android.bluetooth.TestUtils; import com.android.bluetooth.btservice.AdapterService; Loading Loading @@ -71,12 +72,14 @@ public class TbsGenericTest { private @Captor ArgumentCaptor<Integer> mDefaultGtbsTechnologyCaptor; private @Captor ArgumentCaptor<TbsGatt.Callback> mTbsGattCallback; private static Context mContext; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mAdapter = BluetoothAdapter.getDefaultAdapter(); mContext = getInstrumentation().getTargetContext(); // Default TbsGatt mock behavior doReturn(true).when(mTbsGatt).init(mGtbsCcidCaptor.capture(), mGtbsUciCaptor.capture(), Loading @@ -97,6 +100,7 @@ public class TbsGenericTest { doReturn(true).when(mTbsGatt).clearIncomingCall(); doReturn(true).when(mTbsGatt).setCallFriendlyName(anyInt(), anyString()); doReturn(true).when(mTbsGatt).clearFriendlyName(); doReturn(mContext).when(mTbsGatt).getContext(); mTbsGeneric = new TbsGeneric(); mTbsGeneric.init(mTbsGatt); Loading Loading
android/app/src/com/android/bluetooth/tbs/TbsGeneric.java +60 −8 Original line number Diff line number Diff line Loading @@ -18,15 +18,14 @@ package com.android.bluetooth.tbs; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattDescriptor; import android.bluetooth.BluetoothGattServerCallback; import android.bluetooth.BluetoothGattService; import android.bluetooth.BluetoothLeCallControl; import android.bluetooth.BluetoothLeCall; import android.bluetooth.BluetoothLeCallControl; import android.bluetooth.IBluetoothLeCallControlCallback; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.media.AudioManager; import android.net.Uri; import android.os.ParcelUuid; import android.os.RemoteException; Loading Loading @@ -115,6 +114,28 @@ public class TbsGeneric { private Bearer mForegroundBearer = null; private int mLastRequestIdAssigned = 0; private List<String> mUriSchemes = new ArrayList<>(Arrays.asList("tel")); private Receiver mReceiver = null; private int mStoredRingerMode = -1; private final class Receiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { int ringerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1); if (ringerMode < 0 || ringerMode == mStoredRingerMode) return; mStoredRingerMode = ringerMode; if (isSilentModeEnabled()) { mTbsGatt.setSilentModeFlag(); } else { mTbsGatt.clearSilentModeFlag(); } } } }; public boolean init(TbsGatt tbsGatt) { if (DBG) { Loading @@ -128,8 +149,32 @@ public class TbsGeneric { return false; } return mTbsGatt.init(ccid, UCI, mUriSchemes, true, true, DEFAULT_PROVIDER_NAME, DEFAULT_BEARER_TECHNOLOGY, mTbsGattCallback); if (!mTbsGatt.init(ccid, UCI, mUriSchemes, true, true, DEFAULT_PROVIDER_NAME, DEFAULT_BEARER_TECHNOLOGY, mTbsGattCallback)) { Log.e(TAG, " TbsGatt init failed"); return false; } AudioManager mAudioManager = mTbsGatt.getContext() .getSystemService(AudioManager.class); if (mAudioManager == null) { Log.w(TAG, " AudioManager is not available"); return true; } // read initial value of ringer mode mStoredRingerMode = mAudioManager.getRingerMode(); if (isSilentModeEnabled()) { mTbsGatt.setSilentModeFlag(); } else { mTbsGatt.clearSilentModeFlag(); } mReceiver = new Receiver(); mTbsGatt.getContext().registerReceiver(mReceiver, new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION)); return true; } public void cleanup() { Loading @@ -138,11 +183,18 @@ public class TbsGeneric { } if (mTbsGatt != null) { if (mReceiver != null) { mTbsGatt.getContext().unregisterReceiver(mReceiver); } mTbsGatt.cleanup(); mTbsGatt = null; } } private boolean isSilentModeEnabled() { return mStoredRingerMode != AudioManager.RINGER_MODE_NORMAL; } private Bearer getBearerByToken(String token) { synchronized (mBearerList) { for (Bearer bearer : mBearerList) { Loading
android/app/tests/unit/src/com/android/bluetooth/tbs/TbsGenericTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import androidx.test.InstrumentationRegistry; import androidx.test.filters.MediumTest; import androidx.test.rule.ServiceTestRule; import androidx.test.runner.AndroidJUnit4; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import com.android.bluetooth.TestUtils; import com.android.bluetooth.btservice.AdapterService; Loading Loading @@ -71,12 +72,14 @@ public class TbsGenericTest { private @Captor ArgumentCaptor<Integer> mDefaultGtbsTechnologyCaptor; private @Captor ArgumentCaptor<TbsGatt.Callback> mTbsGattCallback; private static Context mContext; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mAdapter = BluetoothAdapter.getDefaultAdapter(); mContext = getInstrumentation().getTargetContext(); // Default TbsGatt mock behavior doReturn(true).when(mTbsGatt).init(mGtbsCcidCaptor.capture(), mGtbsUciCaptor.capture(), Loading @@ -97,6 +100,7 @@ public class TbsGenericTest { doReturn(true).when(mTbsGatt).clearIncomingCall(); doReturn(true).when(mTbsGatt).setCallFriendlyName(anyInt(), anyString()); doReturn(true).when(mTbsGatt).clearFriendlyName(); doReturn(mContext).when(mTbsGatt).getContext(); mTbsGeneric = new TbsGeneric(); mTbsGeneric.init(mTbsGatt); Loading