简体   繁体   English

如何基于谷歌最新的 Android 拨号器应用程序(或基于原版的 ROM,如 Lineage OS)制作拨号器?

[英]How to make a dialer based on Google's Android latest dialer app (or of a Vanilla based ROM such as Lineage OS)?

Background背景

Starting from Android M, it's possible to make a replacement to the dialer app of the OS, meaning that taking phone calls could show your own customized UI.从 Android M 开始,可以替换操作系统的拨号器应用程序,这意味着接听电话可以显示您自己的自定义 UI。

This is done by extending InCallService class, and having an Activity that handles dialing intents:这是通过扩展InCallService类并拥有一个处理拨号意图的 Activity 来完成的:

<service android:name="your.package.YourInCallServiceImplementation"
           android:permission="android.permission.BIND_INCALL_SERVICE">
       <meta-data android:name="android.telecom.IN_CALL_SERVICE_UI" android:value="true" />
       <meta-data android:name="android.telecom.IN_CALL_SERVICE_RINGING"
           android:value="true" />
       <intent-filter>
           <action android:name="android.telecom.InCallService"/>
       </intent-filter>
  </service>

<activity android:name="your.package.YourDialerActivity"
            android:label="@string/yourDialerActivityLabel">
       <intent-filter>
            <action android:name="android.intent.action.DIAL" />
            <category android:name="android.intent.category.DEFAULT" />
       </intent-filter>
  </activity>

And to request to be the default dialer, you can use:要请求成为默认拨号程序,您可以使用:

private fun offerReplacingDefaultDialer() {
    if (getSystemService(TelecomManager::class.java).defaultDialerPackage != packageName) {
        startActivity( Intent(ACTION_CHANGE_DEFAULT_DIALER)
                .putExtra(EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, packageName))

    }
}

The problem问题

The API is so big that very few apps even tried such a thing, and when they did, they made a very minimal implementation compared to the built-in one. API 是如此之大,以至于很少有应用程序甚至尝试过这样的事情,当他们这样做时,与内置的相比,他们做了一个非常小的实现。 Even compared to Google's dialer.甚至与谷歌的拨号器相比。

Example of features that should be implemented, by just looking on the UI of the dialer during calls: mute, keypad, speaker, add call (conference), hold, various states, video calls (?), ...应实现的功能示例,只需在通话期间查看拨号器的 UI:静音、键盘、扬声器、添加通话(会议)、保持、各种状态、视频通话 (?)、...

What I've found我发现了什么

Trying to make my own solution, I've found a sample repository ( here - "simple-phone" ) that I've made my own fork of ( here ), only to find out how many things I should implement to make something that is at least as feature-rich as what Google offers.尝试制作自己的解决方案时,我找到了一个示例存储库(此处- “simple-phone”),我已经制作了自己的分支(此处),只是为了找出我应该实现多少东西来制作一些东西至少与 Google 提供的功能一样丰富。

I've also searched if others have cloned the Dialer before, but found out only 2, and they are quite old versions of the Dialer (one here which doesn't have the UI of the during-call, another here which has some issues with call-log, and has a lot of deprecated and forbidden things being used ), and with some bugs that I've stopped to even consider using.我也搜索过其他人之前是否克隆过拨号器,但只找到了 2 个,而且它们是相当旧的拨号器版本(这里一个没有通话期间的 UI,另一个有一些问题带有呼叫日志,并且有很多不推荐使用和禁止使用的东西),并且有一些我已经停止考虑使用的错误。

So I tried to clone the project that I've found of Android itself,here .因此,我尝试在此处克隆我发现的 Android 项目。 Sadly it has a very weird folders structure, that made it impossible to understand what should be done with it and how to even import it on the IDE :可悲的是,它有一个非常奇怪的文件夹结构,这使得它无法理解应该用它做什么以及如何在 IDE 上导入它:

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

But somehow the repositories that I've found had a different folders structure, meaning they know it should be modified somehow, or that it has changed since then.但是不知何故,我发现的存储库具有不同的文件夹结构,这意味着他们知道应该以某种方式对其进行修改,或者从那时起它已经更改。

I even tried to clone dialer apps from custom ROMs (searching on Github, here ), but got similar issues.我什至尝试从自定义 ROM 克隆拨号器应用程序(在 Github 上搜索, 这里),但遇到了类似的问题。

And yet somehow developers managed to make it work.然而不知何故,开发人员设法使其工作。 If you try out "Lineage OS Phone" app from ApkMirror, you will most likely have it working fine, especially if you use v11 instead of v19 (v19 worked for me on Pixel 2 but not on Note 8, yet v11 worked on both).如果您从 ApkMirror 试用“Lineage OS Phone”应用程序,您很可能会正常工作,特别是如果您使用v11而不是v19 (v19 在 Pixel 2 上对我有效,但在 Note 8 上无效,但 v11 在两者上都有效) .

It is also said that Google's Dialer is now available on more and more devices ( here ), but for some reason I don't see it available for many (tested on Note 8).也有人说谷歌的拨号器现在可以在越来越多的设备上使用( 这里),但由于某种原因,我看不到它对许多设备可用(在 Note 8 上测试过)。

It reminds me of so many problems I had when I tried to clone the launcher and make my own one (made repository here ), back in Eclipse IDE time, 4 years ago.它让我想起了 4 年前,在 Eclipse IDE 时代,我尝试克隆启动器并制作自己的启动器(在此处制作存储库)时遇到的许多问题。 It's just weird to me that this would be as hard as it was for the launcher...这对我来说很奇怪,这和启动器一样难......

So far, the only thing that worked for me is to use one of the sample repositories ( here ) , and made a working fork of it ( here ), but as I wrote it has various issues, such as not able to handle call-logs, and when I try to update its targetSdk, it has some DB issues (like what's written here ).到目前为止,唯一对我有用的是使用其中一个示例存储库(此处),并对其进行了工作分叉( 此处),但正如我所写的那样,它存在各种问题,例如无法处理调用-日志,当我尝试更新它的 targetSdk 时,它有一些数据库问题(比如这里写的)。 Maybe even more issues that I didn't notice.也许还有更多我没有注意到的问题。

Update: found yet another repository, here ("Koler") , that generally works fine.更新:在这里 ("Koler")找到了另一个存储库,它通常可以正常工作。 Not the AOSP one, but can help in some cases to understand how things work.不是 AOSP,但在某些情况下可以帮助理解事情是如何运作的。

The questions问题

  1. How can I clone the latest version of the Dialer app and use it?如何克隆最新版本的 Dialer 应用程序并使用它? What are the steps to achieve a build-able project ?实现可构建项目的步骤是什么?

  2. Why does it have to be so hard?为什么一定要这么难? Will the solution you offer work for other types of apps that are inside of Android (like the launcher, for example) ?您提供的解决方案是否适用于 Android 内部的其他类型的应用程序(例如启动器)?

  3. Alternatively to the one of Vanilla Android OS (meaning if there is no good solution to using it), is it possible to do it for a custom ROM that gets updated from time to time, like Lineage OS ?作为 Vanilla Android OS 的替代方案(意思是如果没有好的解决方案来使用它),是否可以为不时更新的自定义 ROM 执行此操作,例如 Lineage OS ?

How can I clone the latest version of the Dialer app and use it?如何克隆最新版本的 Dialer 应用程序并使用它?

You can't.你不能。 AOSP Dialer based projects heavily rely on the AOSP build system, internal libraries, and APIs, which simply aren't available outside of a full AOSP context.基于 AOSP 拨号器的项目严重依赖 AOSP 构建系统、内部库和 API,这些在完整的 AOSP 上下文之外根本不可用。

What are the steps to achieve a build-able project?实现可构建项目的步骤是什么?

You won't get very far with building it in Android Studio, unless you put in a lot of work with reworking or removing things that prevent you from migrating it to the Gradle build system.在 Android Studio 中构建它不会走得太远,除非您投入大量的工作来修改或删除阻止您将其迁移到 Gradle 构建系统的东西。

Why does it have to be so hard?为什么一定要这么难?

It's simply not intended to be built outside of AOSP by default.默认情况下,它根本不打算在 AOSP 之外构建。 Google engineers don't care, they have a full AOSP checkout. Google 工程师不在乎,他们有完整的 AOSP 结帐。 Custom ROM developers usually don't care as well, most of them have a full checkout of their modified source as well.自定义 ROM 开发人员通常也不在乎,他们中的大多数人也对修改后的源进行了全面检查。

Will the solution you offer work for other types of apps that are inside of Android (like the launcher, for example)?您提供的解决方案是否适用于 Android 内部的其他类型的应用程序(例如启动器)?

The only solution to build it with Android Studio is using Gradle (an then using Import, as you already found).使用 Android Studio 构建它的唯一解决方案是使用 Gradle(然后使用 Import,正如您已经发现的那样)。 Some apps include a build.gradle, whether it works you'll have to see.一些应用程序包含一个 build.gradle,它是否有效你必须看到。 The launcher (packages/apps/Launcher3 in AOSP, packages/apps/Trebuchet in CM/LineageOS) ships a build.gradle that was made by Google (for whatever reason), intended for building the Launcher externally.启动器(AOSP 中的 packages/apps/Launcher3,CM/LineageOS 中的 packages/apps/Trebuchet)附带了一个由 Google(无论出于何种原因)制作的 build.gradle,用于在外部构建 Launcher。 Again, you'll have to see if it works.同样,你必须看看它是否有效。

Alternatively to the one of Vanilla Android OS, is it possible to do it for a custom ROM that gets updated from time to time, like Lineage OS?作为 Vanilla Android OS 的替代方案,是否可以为不时更新的自定义 ROM 执行此操作,例如 Lineage OS?

As already stated earlier, most Custom ROM developers have a full source checkout, so they usually don't care about using Gradle (or Android Studio).如前所述,大多数自定义 ROM 开发人员都有完整的源代码检查,因此他们通常不关心使用 Gradle(或 Android Studio)。 Some LineageOS apps (Jelly/Browser, Eleven/Music, and some others) received Gradle support to allow contributors to test changes without having a full source checkout (which can be 70GB and more), but that only happened on LineageOS' own apps so far, not anything that is also used upstream by AOSP.一些 LineageOS 应用程序(Jelly/Browser、Eleven/Music 和其他一些)获得了 Gradle 支持,允许贡献者在没有完整的源代码检查(可能是 70GB 或更多)的情况下测试更改,但这仅发生在 LineageOS 自己的应用程序上,所以到目前为止,还没有 AOSP 在上游使用的任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM