public void registerPhoneAccount(PhoneAccount account) {
try {
Log.startSession("TSI.rPA");
synchronized (mLock) {
if (!((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE))
.isVoiceCapable()) {
Log.w(this,
"registerPhoneAccount not allowed on non-voice capable device.");
return;
}
try {
enforcePhoneAccountModificationForPackage(
account.getAccountHandle().getComponentName().getPackageName());
if (account.hasCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)) {
enforceRegisterSelfManaged();
if (account.hasCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER) ||
account.hasCapabilities(
PhoneAccount.CAPABILITY_CONNECTION_MANAGER) ||
account.hasCapabilities(
PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) {
throw new SecurityException("Self-managed ConnectionServices " +
"cannot also be call capable, connection managers, or " +
"SIM accounts.");
}
// For self-managed CS, the phone account registrar will override the
// label the user has set for the phone account. This ensures the
// self-managed cs implementation can't spoof their app name.
}
if (account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) {
enforceRegisterSimSubscriptionPermission();
}
if (account.hasCapabilities(PhoneAccount.CAPABILITY_MULTI_USER)) {
enforceRegisterMultiUser();
}
Bundle extras = account.getExtras();
if (extras != null
&& extras.getBoolean(PhoneAccount.EXTRA_SKIP_CALL_FILTERING)) {
enforceRegisterSkipCallFiltering();
}
final int callingUid = Binder.getCallingUid();
if (callingUid != Process.SHELL_UID) {
enforceUserHandleMatchesCaller(account.getAccountHandle());
}
if (TextUtils.isEmpty(account.getGroupId())
&& mContext.checkCallingOrSelfPermission(MODIFY_PHONE_STATE)
!= PackageManager.PERMISSION_GRANTED) {
Log.w(this, "registerPhoneAccount - attempt to set a"
+ " group from a non-system caller.");
// Not permitted to set group, so null it out.
account = new PhoneAccount.Builder(account)
.setGroupId(null)
.build();
}
final long token = Binder.clearCallingIdentity();
try {
mPhoneAccountRegistrar.registerPhoneAccount(account);
} finally {
Binder.restoreCallingIdentity(token);
}
} catch (Exception e) {
Log.e(this, e, "registerPhoneAccount %s", account);
throw e;
}
}
} finally {
Log.endSession();
}
}
//change the above mentioned condition to false to make it capable device and hfp works from application side