一、撥號流程總結
DialpadFragment提供用戶撥號的交互界面 CallIntentBuilder創建撥號請求的intent對象 TelecomManager繼續傳遞撥號請求intent對象
二、ITelecomService接收撥號請求服務
/packages/services/Telecomm/src/com/android/server/telecom
這個代碼庫編譯出來就是Telecom.apk Android應用程序,後面統一稱爲Telecom應用
<service android:name=".components.TelecomService"
android:singleUser="true"
android:process="system">
<intent-filter>
<action android:name="android.telecom.ITelecomService" />
</intent-filter>
</service>
指定進程爲system,也就是這個服務將會運行在system_server系統,唯一的action爲android.telecom.ITelecomService.
❝注意:Dialer應用的com.android.dialer進程提供用戶撥號界面並且響應用戶的撥號請求,把撥號請求包裝成action爲Intent.ACTION_CALL的intent對象,通過調用ITelecomService提供的placeCall接口,將撥號請求intent發送給了Telelcom應用(system_server進程),完成了第一次跨進程的服務調用。
❞
看一下TelecomServiceImpl.java文件中的placeCall方法
public void placeCall(Uri handle, Bundle extras, String callingPackage) {
try {
Log.startSession("TSI.pC");
enforceCallingPackage(callingPackage);
PhoneAccountHandle phoneAccountHandle = null;
if (extras != null) {
phoneAccountHandle = extras.getParcelable(
TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE);
if (extras.containsKey(TelecomManager.EXTRA_IS_HANDOVER)) {
// This extra is for Telecom use only so should never be passed in.
extras.remove(TelecomManager.EXTRA_IS_HANDOVER);
}
}
boolean isSelfManaged = phoneAccountHandle != null &&
isSelfManagedConnectionService(phoneAccountHandle);
if (isSelfManaged) {
mContext.enforceCallingOrSelfPermission(Manifest.permission.MANAGE_OWN_CALLS,
"Self-managed ConnectionServices require MANAGE_OWN_CALLS permission.");
if (!callingPackage.equals(
phoneAccountHandle.getComponentName().getPackageName())
&& !canCallPhone(callingPackage,
"CALL_PHONE permission required to place calls.")) {
// The caller is not allowed to place calls, so we want to ensure that it
// can only place calls through itself.
throw new SecurityException("Self-managed ConnectionServices can only "
+ "place calls through their own ConnectionService.");
}
} else if (!canCallPhone(callingPackage, "placeCall")) {
throw new SecurityException("Package " + callingPackage
+ " is not allowed to place phone calls");
}
三、源碼:
https://github.com/ruigege66/Android/tree/master/ContactsTest
CSDN:https://blog.csdn.net/weixin_44630050 博客園:https://www.cnblogs.com/ruigege0000/ 歡迎關注微信公衆號:傅里葉變換,個人賬號,僅用於技術交流