I want to implement "android.telephony" library for Voip dialer app. So according to this https://developer.android.com/reference/android/telecom/ConnectionService I am trying to register PhoneAccount. I am doing like below,
private void registerPhoneAcc(String calleeURI, String phoneNumber) {
TelecomManager telecomManager = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
telecomManager = (TelecomManager) getContext().getSystemService(Context.TELECOM_SERVICE);
}
ComponentName componentName = new ComponentName(getContext().getPackageName(), String.valueOf(MyConnectionService.class));
PhoneAccountHandle phoneAccountHandle = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
phoneAccountHandle = new PhoneAccountHandle(componentName,"App" );
PhoneAccount phoneAccount = PhoneAccount.builder(phoneAccountHandle, "Primary").setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER).build();
telecomManager.registerPhoneAccount(phoneAccount);
}
}
<service android:name=".app.MyConnectionService"
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
<intent-filter>
<action android:name="android.telecom.ConnectionService" />
</intent-filter>
</service>
Eventhough I have included the permission, I have got below exception
W/System.err: java.lang.SecurityException: PhoneAccount connection service requires BIND_TELECOM_CONNECTION_SERVICE permission.
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at android.os.Parcel.readException(Parcel.java:2013)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at android.os.Parcel.readException(Parcel.java:1959)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at com.android.internal.telecom.ITelecomService$Stub$Proxy.registerPhoneAccount(ITelecomService.java:1019)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at android.telecom.TelecomManager.registerPhoneAccount(TelecomManager.java:990)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at com.app.DialClass.registerPhoneAcc(DialClass.java:828)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at com.app.DialClass.handleMessage(DialClass.java:1114)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at android.os.Looper.loop(Looper.java:176)
2021-02-03 13:58:39.260 24630-24630/com.ex.voip W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6651)
2021-02-03 13:58:39.260 24630-24630/com.ex.voip W/System.err: at java.lang.reflect.Method.invoke(Native Method)
2021-02-03 13:58:39.260 24630-24630/com.ex.voip W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
Manifest,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.ex.voip">
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.group.MICROPHONE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="false" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<application
android:allowBackup="true"
android:allowClearUserData="true"
android:fullBackupContent="false"
android:hardwareAccelerated="false"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:largeHeap="true"
android:usesCleartextTraffic="true"
android:resizeableActivity="false"
android:screenOrientation="portrait"
android:supportsRtl="true"
tools:replace="android:label,android:theme,android:icon"
android:theme="@style/AppThemeNoAction"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".app.LaunchActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity"
android:theme="@style/FullscreenTheme"
tools:replace="android:icon">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".app.NetworkChangeReceiver"
android:label="NetworkChangeReceiver" />
<activity
android:name=".app.MainActivity"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity"
android:theme="@style/AppThemeNoActionBar" />
<activity
android:name=".app.AboutActivity"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".app.SpeedActivity"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".app.Function"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity"/>
<activity
android:name=".app.CallDetails"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".app.AccountDetails"
android:label="@string/title_activity_account_details"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity"
android:theme="@style/AppThemeNoAction.NoActionBar"/>
<activity
android:name=".app.DetailsRecyclerView"
android:screenOrientation="sensorPortrait"
tools:ignore="LockedOrientationActivity"/>
<service android:name=".app.pushnotifications.FCMBroadcastReceiver">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".app.StartService"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name=".app.CallService"
android:exported="true"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<receiver android:name=".app.CallBroadcast"
android:exported="true"/>
<service
android:name=".app.VoipSupportService"
android:exported="false"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service android:name=".app.NotificationService"
android:exported="false"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service android:name=".app.MyConnectionService"
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
<intent-filter>
<action android:name="android.telecom.ConnectionService" />
</intent-filter>
</service>
</application>
</manifest>
Implemented Runtime Permission like this https://stackoverflow.com/a/40490990/11630822
My request for BIND_TELECOM_CONNECTION_SERVICE Permission is getting denied.
Doesn't know the reason for that.
Thanks in Advance.