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


目录
相关文章
|
语音技术
FreeSwitch中音乐功能保持和静音回铃声怎样设置
FreeSwitch中音乐功能保持和静音回铃声怎样设置
|
11月前
|
安全 Android开发 开发者
【软件推荐】屏蔽手机开屏广告
【软件推荐】屏蔽手机开屏广告
|
11月前
|
移动开发
手机h5页面唤起打电话、发短信功能
手机h5页面唤起打电话、发短信功能
|
iOS开发
IOS - 苹果微信不打开收不到新消息提醒怎么办?
IOS - 苹果微信不打开收不到新消息提醒怎么办?
658 0
IOS - 苹果微信不打开收不到新消息提醒怎么办?
程序人生 - 王者荣耀隐身设置,不让好友看到在线状态
程序人生 - 王者荣耀隐身设置,不让好友看到在线状态
240 0
程序人生 - 王者荣耀隐身设置,不让好友看到在线状态
|
数据安全/隐私保护 iOS开发
小技巧 - iPhone手机(IOS系统)玩游戏时关闭所有消息提醒
小技巧 - iPhone手机(IOS系统)玩游戏时关闭所有消息提醒
856 0
小技巧 - iPhone手机(IOS系统)玩游戏时关闭所有消息提醒
Andorid通话自动录音
Andorid通话自动录音
174 0
Andorid通话自动录音
敬业签云便签手机版上已经提醒过的待办事项怎么标记已完成?
敬业签云便签手机版上已经提醒过的待办事项怎么标记已完成? 敬业签云便签是一款专为商务办公族设计的桌面日程安排软件,当实际的待办事项已完成后,可在便签上针对待办事项标记已完成,已完成列表上会有该待办事项的已完成的记录。
1205 0
|
数据安全/隐私保护 关系型数据库 RDS
魅族手机便签的备忘录内容误删了怎么办?
魅族手机便签的备忘录内容误删了怎么办? 大多数人会想到,魅族手机有云服务账号,一般情况下可以在云服务中找回。前提是需要将备忘录内容进行备份,牢记自己的账号密码。
2283 0
苹果手机什么日程安排提醒软件可以事件备忘和随时提醒?
苹果手机上什么日程安排提醒软件可以事件备忘和随时提醒? iPhone手机上有备忘录用来事件备忘,有提醒事项可以日程提醒,iPhone手机上想用一款集备忘与提醒于一体的桌面日程安排提醒软件,可以添加云便签敬业签苹果手机版使用。
1845 0