谷歌Dialer和来电铃声不同步问题修改

简介: 谷歌Dialer和来电铃声不同步问题修改

bug 描述:来电铃声响起后,来电页面隔个2~4秒才起来


解决思路


把原有响铃逻辑稍微延后,等到页面起来后再通知铃声播放。

响铃实际在 Telecomm 中,这个简单

要判断页面是否在前台这个有点挑战,一开始没啥思路,后来分析 log 找到了很明显的地方 DecorView

V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@b9781c9, this = DecorView@383b0ce[LiveWallpaperActivity]
V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@b9781c9, this = DecorView@383b0ce[LiveWallpaperActivity]
V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@a138a1d, this = DecorView@f98de06[Settings$WallpaperSettingsActivity]
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@bcb3e0a, this = DecorView@d2e335f[MainActivity]
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@b9781c9, this = DecorView@383b0ce[LiveWallpaperActivity]


每一个页面(activity) 的根布局为 DecorView,从上面 log 看到在 0/visible 和 4/invisible 之间不断切换,那基本上就可以从这里下手


frameworks\base\core\java\com\android\internal\policy\DecorView.java


    @Override
    public void setVisibility(int visibility) {
        super.setVisibility(visibility);
        String packageName = this.getContext().getPackageName();
    /*if (ViewDebugManager.DEBUG_USER) {
      Log.v("PhoneWindow", "DecorView setVisiblity: visibility = " + visibility
            + ", Parent = " + getParent() + ", this = " + this + " packageName="+packageName);
    }*/
        if ("com.android.dialer".equals(packageName)
     || "com.google.dialer".equals(packageName)) {
            getContext().sendBroadcast(new android.content.Intent("com.android.action.activityChange")
                .putExtra("visibility", visibility));
        }
    }

通知已经发出,接下来去 Telecomm 中接收处理响铃

vendor\mediatek\proprietary\packages\services\Telecomm\src\com\android\server\telecom\Ringer.java

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
    public Ringer(
            InCallTonePlayer.Factory playerFactory,
            Context context,
            SystemSettingsUtil systemSettingsUtil,
            AsyncRingtonePlayer asyncRingtonePlayer,
            RingtoneFactory ringtoneFactory,
            Vibrator vibrator,
            VibrationEffectProxy vibrationEffectProxy,
            InCallController inCallController) {
        mIsHapticPlaybackSupportedByDevice =
                mSystemSettingsUtil.isHapticPlaybackSupported(mContext);
     //add
     android.util.Log.d("Ringer", "Initializes the Ringer"); 
       mContext.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                 int visibility = intent.getIntExtra("visibility", 4);
                 if (visibility == 0) {
                    if (!justRingOnce) {
                        justRingOnce = true;
                        startRinging(foregroundCall, isHfpDeviceAttached, true);
                    }
                 }else {
                     justRingOnce = false;
                 }
            }
        }, new IntentFilter("com.android.action.activityChange"));
       //end
    }
  //add
    Call foregroundCall;
    boolean isHfpDeviceAttached;
    boolean justRingOnce;
    public boolean startRinging(Call foregroundCall, boolean isHfpDeviceAttached) {
      this.foregroundCall = foregroundCall;
        this.isHfpDeviceAttached = isHfpDeviceAttached;
    return false;
  }
  //end
  public boolean startRinging(Call foregroundCall, boolean isHfpDeviceAttached, boolean newFun) {
        if (foregroundCall == null) {
            /// M: ALPS03787956 Fix wtf log warning. @{
            /// Hand up the call immediately when ringing. Then the foreground call will
            /// change to null, but call audio is start ringing at the same time.
            /// Log.wtf will occur in this case.
            /// Solution:
            /// Call audio can handle this case, so change Log.wtf to Log.i here.
            Log.i(this, "startRinging called with null foreground call.");
            /// @}
            return false;
        }


目录
打赏
0
0
0
0
6
分享
相关文章
Oracle Linux 10 - Oracle 提供支持 RHEL 兼容发行版
Oracle Linux 10 - Oracle 提供支持 RHEL 兼容发行版
135 11
Oracle Linux 10 - Oracle 提供支持 RHEL 兼容发行版
|
8月前
|
UED
淘宝上货接口(淘宝发货接口)
淘宝上货接口是商家实现订单发货和物流跟踪的重要工具,可自动化处理订单,减少人工错误,提升用户体验。本文从接口概述、功能、使用方法及优缺点四方面详细介绍。
巧用通义灵码,提升前端研发效率
本次分享,主题是利用通义灵码提升前端研发效率。分享内容主要包括以下几部分:首先,我将从前端开发的角度介绍对通义灵码的基本认识;其次,我将展示通义灵码在日常研发中的应用案例;然后,我将通过实例说明,良好的设计能够显著提升通义灵码的效果。在第四个部分,我将介绍通义灵码的企业知识库以及如何利用 RAG 构建团队智能研发助手。最后,我将总结本次分享并展望未来方向。
阿里云OS Copilot体验
阿里云OS Copilot是面向开发者和运维的智能助手,简化云应用管理,通过自然语言处理支持命令行交互,提供智能推荐及代码解析,提升效率。集成阿里云服务,实现从开发到部署的全链条支持。虽然在特定场景和文档详尽度上有改进空间,但整体上,OS Copilot是提升云工作流效率的有效工具。
Linux系统之smem命令的基本使用
【7月更文挑战第1天】Linux系统之smem命令的基本使用
258 3
AIGC:聊聊如何用openai帮我们进行情感分析(Huggingface——transformer)
AIGC:聊聊如何用openai帮我们进行情感分析(Huggingface——transformer)
c++数组详细介绍(一)
前言 深入理解C++的数组和字符串是成为熟练C++程序员的重要一步。本文将探索C++中数组和字符串的基本概念,从基础到进阶,包括数组的声明、初始化、访问和多维数组的操作,以及字符串类的使用和与字符数组的转换。还将涉及异常处理、动态内存分配、STL中的其他容器、常用字符串操作。
208 0
OpenCV(十七):拉普拉斯图像金字塔
OpenCV(十七):拉普拉斯图像金字塔
384 0
28个SpringBoot项目中常用注解,日常开发、求职面试不再懵圈(一)
28个SpringBoot项目中常用注解,日常开发、求职面试不再懵圈
304 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问