谷歌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;
        }


目录
相关文章
|
5月前
|
Oracle Cloud Native 关系型数据库
Oracle Linux 10 - Oracle 提供支持 RHEL 兼容发行版
Oracle Linux 10 - Oracle 提供支持 RHEL 兼容发行版
237 11
Oracle Linux 10 - Oracle 提供支持 RHEL 兼容发行版
|
11月前
|
UED
淘宝上货接口(淘宝发货接口)
淘宝上货接口是商家实现订单发货和物流跟踪的重要工具,可自动化处理订单,减少人工错误,提升用户体验。本文从接口概述、功能、使用方法及优缺点四方面详细介绍。
|
8月前
|
人工智能 自然语言处理 前端开发
巧用通义灵码,提升前端研发效率
本次分享,主题是利用通义灵码提升前端研发效率。分享内容主要包括以下几部分:首先,我将从前端开发的角度介绍对通义灵码的基本认识;其次,我将展示通义灵码在日常研发中的应用案例;然后,我将通过实例说明,良好的设计能够显著提升通义灵码的效果。在第四个部分,我将介绍通义灵码的企业知识库以及如何利用 RAG 构建团队智能研发助手。最后,我将总结本次分享并展望未来方向。
|
存储 SQL 关系型数据库
MySQL的事务隔离级别
【10月更文挑战第17天】MySQL的事务隔离级别
279 43
|
11月前
|
存储 人工智能 安全
从梦想到现实:十年见证AI自动化漏洞修复的演变
2014年,我怀揣着利用科技创造更安全数字世界的梦想,提出了通过云平台自动化修复第三方网站漏洞的构想。十年后的2024年,随着AI技术的崛起,这一梦想已成为现实。如今,用户只需简单注册并安装插件,AI系统就能自动检测、修复漏洞,整个过程高效、智能。AI不仅提升了系统的可靠性和效率,还具备自我学习能力,使安全防护更加主动。未来,我将继续用AI探索更多可能,推动技术的发展,不断完善这个充满智慧与安全的数字世界。
248 3
从梦想到现实:十年见证AI自动化漏洞修复的演变
|
SQL Oracle 关系型数据库
关系型数据库Oracle结束 RMAN 会话:
【7月更文挑战第25天】
379 1
|
缓存 监控 Linux
Linux系统之smem命令的基本使用
【7月更文挑战第1天】Linux系统之smem命令的基本使用
336 3
|
人工智能 自然语言处理 前端开发
AIGC:聊聊如何用openai帮我们进行情感分析(Huggingface——transformer)
AIGC:聊聊如何用openai帮我们进行情感分析(Huggingface——transformer)
|
Java
错误:has been compiled by a more recent version of the Java Runtime (class file version 56.0)
错误:has been compiled by a more recent version of the Java Runtime (class file version 56.0)
6479 0
|
编解码 算法 计算机视觉
OpenCV(十七):拉普拉斯图像金字塔
OpenCV(十七):拉普拉斯图像金字塔
484 0