Fix test breakage when phone bluetooth is on
When the phone's bluetooth is enabled, TelecomSystemTest will fail with
a permission error in BluetoothPhoneServiceImpl. This change introduces
a new factory to facilitate mocking of BluetoothPhoneServiceImpl.
Change-Id: I58e1d5532a7f55580d37158fee27209e3de24988
diff --git a/src/com/android/server/telecom/BluetoothPhoneServiceImpl.java b/src/com/android/server/telecom/BluetoothPhoneServiceImpl.java
index dab4545..b5fe83c 100644
--- a/src/com/android/server/telecom/BluetoothPhoneServiceImpl.java
+++ b/src/com/android/server/telecom/BluetoothPhoneServiceImpl.java
@@ -45,7 +45,13 @@
* Bluetooth headset manager for Telecom. This class shares the call state with the bluetooth device
* and accepts call-related commands to perform on behalf of the BT device.
*/
-public final class BluetoothPhoneServiceImpl {
+public class BluetoothPhoneServiceImpl {
+
+ public interface BluetoothPhoneServiceImplFactory {
+ BluetoothPhoneServiceImpl makeBluetoothPhoneServiceImpl(Context context,
+ TelecomSystem.SyncRoot lock, CallsManager callsManager,
+ PhoneAccountRegistrar phoneAccountRegistrar);
+ }
private static final String TAG = "BluetoothPhoneService";
diff --git a/src/com/android/server/telecom/TelecomSystem.java b/src/com/android/server/telecom/TelecomSystem.java
index 529b34b..7ebcddc 100644
--- a/src/com/android/server/telecom/TelecomSystem.java
+++ b/src/com/android/server/telecom/TelecomSystem.java
@@ -117,7 +117,9 @@
HeadsetMediaButtonFactory headsetMediaButtonFactory,
ProximitySensorManagerFactory proximitySensorManagerFactory,
InCallWakeLockControllerFactory inCallWakeLockControllerFactory,
- CallAudioManager.AudioServiceFactory audioServiceFactory) {
+ CallAudioManager.AudioServiceFactory audioServiceFactory,
+ BluetoothPhoneServiceImpl.BluetoothPhoneServiceImplFactory
+ bluetoothPhoneServiceImplFactory) {
mContext = context.getApplicationContext();
mMissedCallNotifier = missedCallNotifier;
@@ -140,7 +142,7 @@
mCallsManager.setRespondViaSmsManager(mRespondViaSmsManager);
mContext.registerReceiver(mUserSwitchedReceiver, USER_SWITCHED_FILTER);
- mBluetoothPhoneServiceImpl = new BluetoothPhoneServiceImpl(
+ mBluetoothPhoneServiceImpl = bluetoothPhoneServiceImplFactory.makeBluetoothPhoneServiceImpl(
mContext, mLock, mCallsManager, mPhoneAccountRegistrar);
mCallIntentProcessor = new CallIntentProcessor(mContext, mCallsManager);
mTelecomBroadcastIntentProcessor = new TelecomBroadcastIntentProcessor(
diff --git a/src/com/android/server/telecom/components/TelecomService.java b/src/com/android/server/telecom/components/TelecomService.java
index 1f77759..3d24aa2 100644
--- a/src/com/android/server/telecom/components/TelecomService.java
+++ b/src/com/android/server/telecom/components/TelecomService.java
@@ -25,12 +25,14 @@
import android.os.ServiceManager;
import com.android.internal.telephony.CallerInfoAsyncQuery;
+import com.android.server.telecom.BluetoothPhoneServiceImpl;
import com.android.server.telecom.CallAudioManager;
import com.android.server.telecom.CallerInfoAsyncQueryFactory;
import com.android.server.telecom.CallsManager;
import com.android.server.telecom.HeadsetMediaButton;
import com.android.server.telecom.HeadsetMediaButtonFactory;
import com.android.server.telecom.InCallWakeLockControllerFactory;
+import com.android.server.telecom.PhoneAccountRegistrar;
import com.android.server.telecom.ProximitySensorManagerFactory;
import com.android.server.telecom.InCallWakeLockController;
import com.android.server.telecom.Log;
@@ -111,6 +113,16 @@
return IAudioService.Stub.asInterface(
ServiceManager.getService(Context.AUDIO_SERVICE));
}
+ },
+ new BluetoothPhoneServiceImpl.BluetoothPhoneServiceImplFactory() {
+ @Override
+ public BluetoothPhoneServiceImpl makeBluetoothPhoneServiceImpl(
+ Context context, TelecomSystem.SyncRoot lock,
+ CallsManager callsManager,
+ PhoneAccountRegistrar phoneAccountRegistrar) {
+ return new BluetoothPhoneServiceImpl(context, lock,
+ callsManager, phoneAccountRegistrar);
+ }
}
));
}
diff --git a/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java b/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java
index 74dc365..75a4429 100644
--- a/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java
+++ b/tests/src/com/android/server/telecom/tests/TelecomSystemTest.java
@@ -50,9 +50,9 @@
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telecom.VideoProfile;
-import android.telephony.TelephonyManager;
import com.android.internal.telecom.IInCallAdapter;
+import com.android.server.telecom.BluetoothPhoneServiceImpl;
import com.android.server.telecom.CallAudioManager;
import com.android.server.telecom.CallsManager;
import com.android.server.telecom.HeadsetMediaButton;
@@ -61,6 +61,7 @@
import com.android.server.telecom.InCallWakeLockControllerFactory;
import com.android.server.telecom.Log;
import com.android.server.telecom.MissedCallNotifier;
+import com.android.server.telecom.PhoneAccountRegistrar;
import com.android.server.telecom.ProximitySensorManager;
import com.android.server.telecom.ProximitySensorManagerFactory;
import com.android.server.telecom.TelecomSystem;
@@ -85,6 +86,7 @@
@Mock HeadsetMediaButton mHeadsetMediaButton;
@Mock ProximitySensorManager mProximitySensorManager;
@Mock InCallWakeLockController mInCallWakeLockController;
+ @Mock BluetoothPhoneServiceImpl mBluetoothPhoneServiceImpl;
final ComponentName mInCallServiceComponentNameX =
new ComponentName(
@@ -219,6 +221,14 @@
public IAudioService getAudioService() {
return mAudioService;
}
+ },
+ new BluetoothPhoneServiceImpl.BluetoothPhoneServiceImplFactory() {
+ @Override
+ public BluetoothPhoneServiceImpl makeBluetoothPhoneServiceImpl(Context context,
+ TelecomSystem.SyncRoot lock, CallsManager callsManager,
+ PhoneAccountRegistrar phoneAccountRegistrar) {
+ return mBluetoothPhoneServiceImpl;
+ }
});
mComponentContextFixture.setTelecomManager(new TelecomManager(