I am trying to implement ConnectionService, Connection, and registering PhoneAccount for outgoing calls. So far, I have been able to initiate a call using customPhoneAccount but that phone call never goes through, which means the call does not reach the destination phone.
Below is code for PhoneAccount and ConnectionService,
@RequiresApi(api = Build.VERSION_CODES.M)
private void registerConnectionService() {
try {
TelecomManager manager = (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
String connectionServiceId = getConnectionServiceId();
ComponentName componentName = new ComponentName(getApplicationContext(), MyService.class);
PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(componentName, "Dialer");
phoneAccount = manager.getPhoneAccount(phoneAccountHandle);
// Log.i("phoneAccountTekV",phoneAccount.getAddress()+" "+phoneAccount.getCapabilities()+" "+phoneAccount.getLabel());
if (phoneAccount == null) { // no phone account from us registered yet
PhoneAccount.Builder builder = PhoneAccount.builder(phoneAccountHandle, "Dialer");
Uri uri = Uri.parse("tel:9959165743");
//builder.setSubscriptionAddress(uri);
//builder.setAddress(uri);
builder.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER);
//builder.setCapabilities(PhoneAccount.CAPABILITY_CONNECTION_MANAGER);
// builder.setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED);
phoneAccount = builder.build();
manager.registerPhoneAccount(phoneAccount);
Log.i("phoneAccount", "" + phoneAccount.isEnabled());
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.server.telecom",
"com.android.server.telecom.settings.EnableAccountPreferenceActivity"));
startActivity(intent);
}
Log.i("is phoneAccountEnabled", "" + phoneAccount.isEnabled());
} catch (SecurityException se) {
Log.e("registerPhoneAccount", "SecurityException: Ensure all necessary permissions are granted", se);
} catch (IllegalArgumentException iae) {
Log.e("registerPhoneAccount", "IllegalArgumentException: Ensure the PhoneAccount is properly configured", iae);
} catch (RuntimeException re) {
Log.e("registerPhoneAccount", "RuntimeException: An unexpected error occurred", re);
} catch (Exception re) {
Log.e("registerPhoneAccount", "Exception: An unexpected error occurred", re);
}
}
ConnectionService:
@RequiresApi(api = Build.VERSION_CODES.Q)
@RequiresPermission(value = "android.permission.READ_PHONE_STATE")
@Override
public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest originalRequest) {
Uri handle = originalRequest.getAddress();
MyConnection connection = new MyConnection(false, originalRequest,this);
connection.setAddress(handle, TelecomManager.PRESENTATION_ALLOWED);
//connection.setConnectionProperties(Connection.PROPERTY_SELF_MANAGED);
// connection.setDialing();
connection.setInitializing();
connection.setConnectionCapabilities(Connection.CAPABILITY_HOLD | Connection.CAPABILITY_MUTE | Connection.CAPABILITY_SUPPORT_HOLD);
connection.setVideoState(originalRequest.getVideoState());
addCall(connection);
TelecomManager manager = (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
boolean isOut = manager.isOutgoingCallPermitted(connectionManagerPhoneAccount);
Log.i("phoneAccountTekV",connectionManagerPhoneAccount.getUserHandle().toString());
//setAddress(connection,handle);
Log.i("isOutgoingCallPermitted"," isOutgoingCallPermitted-"+isOut);
PhoneAccountHandle ph = manager.getUserSelectedOutgoingPhoneAccount();
List<PhoneAccountHandle> selfHandles =manager.getSelfManagedPhoneAccounts();
List<PhoneAccountHandle> handles =manager.getCallCapablePhoneAccounts();
connection.startOutgoing();
return connection;
}
Logs from LogCat is below:
12:27:49.085 1563-1563/? W/Telecom: Call: maybeOnInCallServiceTrackingChanged() request on a call without a connection service.: ICSBC.oSC(cgag)@C/U
2024-06-24 12:27:49.085 1563-1563/? W/Telecom: Call: maybeOnInCallServiceTrackingChanged() request on a call without a connection service.: ICSBC.oSC(cgaa)@C/Y
2024-06-24 12:27:49.091 1563-6781/? W/WindowManager: Prepare app transition: mNextAppTransitionRequests=[TRANSIT_OPEN, TRANSIT_OPEN], mNextAppTransitionFlags=, displayId: 0 Callers=com.android.server.wm.DisplayContent.prepareAppTransition:6493 com.android.server.wm.TaskFragment.resumeTopActivity:1573 com.android.server.wm.TaskFragment.resumeTopActivity:1307 com.android.server.wm.Task.resumeTopActivityInnerLocked:6451 com.android.server.wm.Task.resumeTopActivityUncheckedLocked:6352
2024-06-24 12:27:49.091 1563-6781/? W/ActivityTaskManager: Tried to set launchTime (0) < mLastActivityLaunchTime (1105139)
2024-06-24 12:27:49.096 1563-1563/? W/Telecom: Call: maybeOnInCallServiceTrackingChanged() request on a call without a connection service.: TSI.pC->CM.fOCP->CM.sOCPA->CM.dSMCP->CM.dSPA->CM.sRCQ->CM.pASP(ctd)@C/M
2024-06-24 12:27:49.096 1563-1563/? W/Telecom: Call: maybeOnInCallServiceTrackingChanged() request on a call without a connection service.: TSI.pC->CM.fOCP->CM.sOCPA->CM.dSMCP->CM.dSPA->CM.sRCQ->CM.pASP(ctd)@C/M
2024-06-24 12:27:49.097 1563-6781/? W/WindowManager: Execute app transition: mNextAppTransitionRequests=[TRANSIT_OPEN, TRANSIT_OPEN], mNextAppTransitionFlags=, displayId: 0 Callers=com.android.server.wm.RootWindowContainer.executeAppTransitionForAllDisplay:2580 com.android.server.wm.ActivityTaskSupervisor.reportResumedActivityLocked:2287 com.android.server.wm.ActivityRecord.completeResumeLocked:6987 com.android.server.wm.Task.minimalResumeActivityLocked:6156 com.android.server.wm.ActivityTaskSupervisor.realStartActivityLocked:1137
2024-06-24 12:27:49.098 1563-1563/? W/Telecom: Call: maybeOnInCallServiceTrackingChanged() request on a call without a connection service.: TSI.pC->CM.fOCP->CM.sOCPA->CM.dSMCP->CM.dSPA->CM.sRCQ->CM.pASP(ctd)@C/M
2024-06-24 12:27:49.099 1224-1461/? W/SecAudioParamPolicy: g_volume_situation_key: did not support legacy situation volumes
2024-06-24 12:27:49.099 32494-32494/? E/m.samsung.crane: Not starting debugger since process cannot load the jdwp agent.
2024-06-24 12:27:49.102 9896-9925/? E/BluetoothAdapterService: getActiveDevices: HearingAidService is null
2024-06-24 12:27:49.107 1563-1563/? W/Telecom: Logging: Log.endSession was called with no session active.
2024-06-24 12:27:49.110 9896-9925/? E/BluetoothAdapterService: getActiveDevices: HearingAidService is null
W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1252 com.android.server.notification.sec.DisplayToast.sendIntentForToastDumpLog:156 com.android.server.notification.sec.DisplayToast.outFile:106 com.android.server.notification.sec.DisplayToast.out:62 com.android.server.notification.NotificationManagerService$12.enqueueToastForDex:3989
2024-06-24 12:27:49.507 5214-5307/? W/Parcel: Expecting binder but got null!
2024-06-24 12:27:49.513 677-677/? W/keymaster_tee: [WRN]begin req PARAMS: A32 B32 P1
2024-06-24 12:27:49.521 677-677/? W/keymaster_tee: [WRN]begin req PARAMS: A32 B32 P1
2024-06-24 12:27:49.529 1121-1121/? E/Sensors: inject_scontext_data: New ssp_data_injection_fd(44)
2024-06-24 12:27:49.530 1563-1718/? W/BroadcastQueue: Background execution not allowed: receiving Intent { act=com.samsung.rcs.contentsharing.action.NUMBER_TOKEN flg=0x10 (has extras) } to com.samsung.crane/.app.PhoneNumberReceiver
2024-06-24 12:27:49.536 1563-1718/? W/BroadcastQueue: Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x1000010 (has extras) } to ProcessRecord{b77a6ce 6726:com.samsung.android.app.cocktailbarservice/u0a52} (pid=6726, uid=10052) requires android.permission.READ_PHONE_STATE due to sender android (uid 1000)
2024-06-24 12:27:49.537 1563-1718/? W/BroadcastQueue: Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x1000010 (has extras) } to ProcessRecord{b77a6ce 6726:com.samsung.android.app.cocktailbarservice/u0a52} (pid=6726, uid=10052) requires android.permission.READ_PHONE_STATE due to sender android (uid 1000)
2024-06-24 12:27:49.537 9896-18745/? E/BluetoothAdapterService: getActiveDevices: HearingAidService is null
can someone please help me ?