From 561abd2398ab1a932c23247d55ff3ab01d0369d9 Mon Sep 17 00:00:00 2001 From: ZhanGSKen Date: Sun, 14 Dec 2025 20:49:11 +0800 Subject: [PATCH] 20251214_204905_236 --- contacts/build.properties | 4 +- .../phonecallui/PhoneCallActivity.java | 1 + .../phonecallui/PhoneCallService.java | 42 +++++++++++-------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/contacts/build.properties b/contacts/build.properties index 0d4672a..ebd21ac 100644 --- a/contacts/build.properties +++ b/contacts/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Sat Dec 13 15:30:16 HKT 2025 +#Sun Dec 14 12:45:32 GMT 2025 stageCount=1 libraryProject= baseVersion=15.14 publishVersion=15.14.0 -buildCount=0 +buildCount=3 baseBetaVersion=15.14.1 diff --git a/contacts/src/main/java/cc/winboll/studio/contacts/phonecallui/PhoneCallActivity.java b/contacts/src/main/java/cc/winboll/studio/contacts/phonecallui/PhoneCallActivity.java index db50fbe..6583d28 100644 --- a/contacts/src/main/java/cc/winboll/studio/contacts/phonecallui/PhoneCallActivity.java +++ b/contacts/src/main/java/cc/winboll/studio/contacts/phonecallui/PhoneCallActivity.java @@ -133,6 +133,7 @@ public class PhoneCallActivity extends AppCompatActivity implements View.OnClick } else if (v.getId() == R.id.tv_phone_hang_up) { phoneCallManager.disconnect(); stopTimer(); + finish(); } } diff --git a/contacts/src/main/java/cc/winboll/studio/contacts/phonecallui/PhoneCallService.java b/contacts/src/main/java/cc/winboll/studio/contacts/phonecallui/PhoneCallService.java index b12a2d3..3ea7ff4 100644 --- a/contacts/src/main/java/cc/winboll/studio/contacts/phonecallui/PhoneCallService.java +++ b/contacts/src/main/java/cc/winboll/studio/contacts/phonecallui/PhoneCallService.java @@ -53,17 +53,16 @@ public class PhoneCallService extends InCallService { LogUtils.e(TAG, "onCallAdded: 通话对象为空,跳过处理"); return; } - - // 注册通话状态回调 - call.registerCallback(mCallCallback); - PhoneCallManager.call = call; - LogUtils.d(TAG, "onCallAdded: 已注册通话回调,通话对象绑定完成"); - // 判断通话类型(来电/去电) CallType callType = judgeCallType(call); if (callType != null) { // 处理有效通话(音量控制、规则校验、启动通话界面) - handleValidCall(call, callType); + if (handleValidCall(call, callType)) { + // 注册通话状态回调 + call.registerCallback(mCallCallback); + PhoneCallManager.call = call; + LogUtils.d(TAG, "onCallAdded: 已注册通话回调,通话对象绑定完成"); + } } else { LogUtils.w(TAG, "onCallAdded: 无法识别通话类型,通话状态=" + call.getState()); } @@ -149,12 +148,12 @@ public class PhoneCallService extends InCallService { * @param call 通话对象 * @param callType 通话类型(来电/去电) */ - private void handleValidCall(Call call, CallType callType) { + private boolean handleValidCall(Call call, CallType callType) { // 1. 获取通话详情与号码(多层空指针防护) Call.Details callDetails = call.getDetails(); if (callDetails == null || callDetails.getHandle() == null) { LogUtils.e(TAG, "handleValidCall: 通话详情或号码信息为空,跳过后续处理"); - return; + return false; } String phoneNumber = callDetails.getHandle().getSchemeSpecificPart(); LogUtils.d(TAG, "handleValidCall: 开始处理通话,号码=" + phoneNumber + ",类型=" + callType); @@ -165,15 +164,17 @@ public class PhoneCallService extends InCallService { LogUtils.e(TAG, "handleValidCall: 获取音频管理器失败,无法处理音量控制"); // 音量控制失败仍启动通话界面,保障基础功能可用 PhoneCallActivity.actionStart(this, phoneNumber, callType); - return; + return true; } // 3. 处理铃声音量(恢复配置音量、拦截时静音) - handleRingerVolumeControl(audioManager, phoneNumber, call); - - // 4. 校验通过,启动通话界面(拦截场景已提前返回,此处直接启动) - PhoneCallActivity.actionStart(this, phoneNumber, callType); - LogUtils.d(TAG, "handleValidCall: 通话校验通过,已启动通话界面"); + if (handleRingerVolumeControl(audioManager, phoneNumber, call)) { + // 4. 校验通过,启动通话界面(拦截场景已提前返回,此处直接启动) + PhoneCallActivity.actionStart(this, phoneNumber, callType); + LogUtils.d(TAG, "handleValidCall: 通话校验通过,已启动通话界面"); + return true; + } + return false; } /** @@ -181,8 +182,9 @@ public class PhoneCallService extends InCallService { * @param audioManager 音频管理器 * @param phoneNumber 通话号码 * @param call 通话对象(用于拦截时断开通话) + * @return true : 继续通话。 false : 通话被中断。 */ - private void handleRingerVolumeControl(AudioManager audioManager, String phoneNumber, Call call) { + private boolean handleRingerVolumeControl(AudioManager audioManager, String phoneNumber, Call call) { // 3.1 获取当前铃声音量 int currentRingerVolume = audioManager.getStreamVolume(AudioManager.STREAM_RING); LogUtils.d(TAG, "handleRingerVolumeControl: 当前铃声音量=" + currentRingerVolume); @@ -207,7 +209,7 @@ public class PhoneCallService extends InCallService { } } catch (SecurityException e) { LogUtils.e(TAG, "handleRingerVolumeControl: 恢复铃声音量失败,权限不足", e); - return; + return false; } // 3.4 校验拦截规则,拦截号码静音+断开通话 @@ -219,6 +221,7 @@ public class PhoneCallService extends InCallService { LogUtils.d(TAG, "handleRingerVolumeControl: 已将铃声音量设为0(静音)"); } catch (SecurityException e) { LogUtils.e(TAG, "handleRingerVolumeControl: 拦截静音失败,权限不足", e); + return false; } // 断开通话 @@ -232,16 +235,19 @@ public class PhoneCallService extends InCallService { LogUtils.d(TAG, "handleRingerVolumeControl: 延迟500ms后,已恢复铃声音量为配置值"); } catch (InterruptedException e) { LogUtils.e(TAG, "handleRingerVolumeControl: 延迟恢复音量失败,线程被中断", e); + return false; } catch (SecurityException e) { LogUtils.e(TAG, "handleRingerVolumeControl: 恢复音量失败,权限不足", e); + return false; } // 拦截完成,直接返回,不启动通话界面 LogUtils.d(TAG, "handleRingerVolumeControl: 拦截处理完成,跳过通话界面启动"); - return; + return false; } LogUtils.d(TAG, "handleRingerVolumeControl: 号码=" + phoneNumber + " 未命中拦截规则,音量控制完成"); + return true; } // ====================== 辅助工具方法区 ======================