summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/telecom
diff options
context:
space:
mode:
authorEric Erfanian <erfanian@google.com>2017-02-22 16:32:36 -0800
committerEric Erfanian <erfanian@google.com>2017-03-01 09:56:52 -0800
commitccca31529c07970e89419fb85a9e8153a5396838 (patch)
treea7034c0a01672b97728c13282a2672771cd28baa /java/com/android/dialer/telecom
parente7ae4624ba6f25cb8e648db74e0d64c0113a16ba (diff)
Update dialer sources.
Test: Built package and system image. This change clobbers the old source, and is an export from an internal Google repository. The internal repository was forked form Android in March, and this change includes modifications since then, to near the v8 release. Since the fork, we've moved code from monolithic to independent modules. In addition, we've switched to Blaze/Bazel as the build sysetm. This export, however, still uses make. New dependencies have been added: - Dagger - Auto-Value - Glide - Libshortcutbadger Going forward, development will still be in Google3, and the Gerrit release will become an automated export, with the next drop happening in ~ two weeks. Android.mk includes local modifications from ToT. Abridged changelog: Bug fixes ● Not able to mute, add a call when using Phone app in multiwindow mode ● Double tap on keypad triggering multiple key and tones ● Reported spam numbers not showing as spam in the call log ● Crash when user tries to block number while Phone app is not set as default ● Crash when user picks a number from search auto-complete list Visual Voicemail (VVM) improvements ● Share Voicemail audio via standard exporting mechanisms that support file attachment (email, MMS, etc.) ● Make phone number, email and web sites in VVM transcript clickable ● Set PIN before declining VVM Terms of Service {Carrier} ● Set client type for outbound visual voicemail SMS {Carrier} New incoming call and incall UI on older devices (Android M) ● Updated Phone app icon ● New incall UI (large buttons, button labels) ● New and animated Answer/Reject gestures Accessibility ● Add custom answer/decline call buttons on answer screen for touch exploration accessibility services ● Increase size of touch target ● Add verbal feedback when a Voicemail fails to load ● Fix pressing of Phone buttons while in a phone call using Switch Access ● Fix selecting and opening contacts in talkback mode ● Split focus for ‘Learn More’ link in caller id & spam to help distinguish similar text Other ● Backup & Restore for App Preferences ● Prompt user to enable Wi-Fi calling if the call ends due to out of service and Wi-Fi is connected ● Rename “Dialpad” to “Keypad” ● Show "Private number" for restricted calls ● Delete unused items (vcard, add contact, call history) from Phone menu Change-Id: I2a7e53532a24c21bf308bf0a6d178d7ddbca4958
Diffstat (limited to 'java/com/android/dialer/telecom')
-rw-r--r--java/com/android/dialer/telecom/TelecomUtil.java212
1 files changed, 212 insertions, 0 deletions
diff --git a/java/com/android/dialer/telecom/TelecomUtil.java b/java/com/android/dialer/telecom/TelecomUtil.java
new file mode 100644
index 000000000..a11e7f77a
--- /dev/null
+++ b/java/com/android/dialer/telecom/TelecomUtil.java
@@ -0,0 +1,212 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.dialer.telecom;
+
+import android.Manifest;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.net.Uri;
+import android.provider.CallLog.Calls;
+import android.support.annotation.Nullable;
+import android.support.v4.content.ContextCompat;
+import android.telecom.PhoneAccount;
+import android.telecom.PhoneAccountHandle;
+import android.telecom.TelecomManager;
+import android.text.TextUtils;
+import android.util.Log;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Performs permission checks before calling into TelecomManager. Each method is self-explanatory -
+ * perform the required check and return the fallback default if the permission is missing,
+ * otherwise return the value from TelecomManager.
+ */
+public class TelecomUtil {
+
+ private static final String TAG = "TelecomUtil";
+ private static boolean sWarningLogged = false;
+
+ public static void showInCallScreen(Context context, boolean showDialpad) {
+ if (hasReadPhoneStatePermission(context)) {
+ try {
+ getTelecomManager(context).showInCallScreen(showDialpad);
+ } catch (SecurityException e) {
+ // Just in case
+ Log.w(TAG, "TelecomManager.showInCallScreen called without permission.");
+ }
+ }
+ }
+
+ public static void silenceRinger(Context context) {
+ if (hasModifyPhoneStatePermission(context)) {
+ try {
+ getTelecomManager(context).silenceRinger();
+ } catch (SecurityException e) {
+ // Just in case
+ Log.w(TAG, "TelecomManager.silenceRinger called without permission.");
+ }
+ }
+ }
+
+ public static void cancelMissedCallsNotification(Context context) {
+ if (hasModifyPhoneStatePermission(context)) {
+ try {
+ getTelecomManager(context).cancelMissedCallsNotification();
+ } catch (SecurityException e) {
+ Log.w(TAG, "TelecomManager.cancelMissedCalls called without permission.");
+ }
+ }
+ }
+
+ public static Uri getAdnUriForPhoneAccount(Context context, PhoneAccountHandle handle) {
+ if (hasModifyPhoneStatePermission(context)) {
+ try {
+ return getTelecomManager(context).getAdnUriForPhoneAccount(handle);
+ } catch (SecurityException e) {
+ Log.w(TAG, "TelecomManager.getAdnUriForPhoneAccount called without permission.");
+ }
+ }
+ return null;
+ }
+
+ public static boolean handleMmi(
+ Context context, String dialString, @Nullable PhoneAccountHandle handle) {
+ if (hasModifyPhoneStatePermission(context)) {
+ try {
+ if (handle == null) {
+ return getTelecomManager(context).handleMmi(dialString);
+ } else {
+ return getTelecomManager(context).handleMmi(dialString, handle);
+ }
+ } catch (SecurityException e) {
+ Log.w(TAG, "TelecomManager.handleMmi called without permission.");
+ }
+ }
+ return false;
+ }
+
+ @Nullable
+ public static PhoneAccountHandle getDefaultOutgoingPhoneAccount(
+ Context context, String uriScheme) {
+ if (hasReadPhoneStatePermission(context)) {
+ return getTelecomManager(context).getDefaultOutgoingPhoneAccount(uriScheme);
+ }
+ return null;
+ }
+
+ public static PhoneAccount getPhoneAccount(Context context, PhoneAccountHandle handle) {
+ return getTelecomManager(context).getPhoneAccount(handle);
+ }
+
+ public static List<PhoneAccountHandle> getCallCapablePhoneAccounts(Context context) {
+ if (hasReadPhoneStatePermission(context)) {
+ return getTelecomManager(context).getCallCapablePhoneAccounts();
+ }
+ return new ArrayList<>();
+ }
+
+ public static boolean isInCall(Context context) {
+ if (hasReadPhoneStatePermission(context)) {
+ return getTelecomManager(context).isInCall();
+ }
+ return false;
+ }
+
+ public static boolean isVoicemailNumber(
+ Context context, PhoneAccountHandle accountHandle, String number) {
+ if (hasReadPhoneStatePermission(context)) {
+ return getTelecomManager(context).isVoiceMailNumber(accountHandle, number);
+ }
+ return false;
+ }
+
+ @Nullable
+ public static String getVoicemailNumber(Context context, PhoneAccountHandle accountHandle) {
+ if (hasReadPhoneStatePermission(context)) {
+ return getTelecomManager(context).getVoiceMailNumber(accountHandle);
+ }
+ return null;
+ }
+
+ /**
+ * Tries to place a call using the {@link TelecomManager}.
+ *
+ * @param context context.
+ * @param intent the call intent.
+ * @return {@code true} if we successfully attempted to place the call, {@code false} if it failed
+ * due to a permission check.
+ */
+ public static boolean placeCall(Context context, Intent intent) {
+ if (hasCallPhonePermission(context)) {
+ getTelecomManager(context).placeCall(intent.getData(), intent.getExtras());
+ return true;
+ }
+ return false;
+ }
+
+ public static Uri getCallLogUri(Context context) {
+ return hasReadWriteVoicemailPermissions(context)
+ ? Calls.CONTENT_URI_WITH_VOICEMAIL
+ : Calls.CONTENT_URI;
+ }
+
+ public static boolean hasReadWriteVoicemailPermissions(Context context) {
+ return isDefaultDialer(context)
+ || (hasPermission(context, Manifest.permission.READ_VOICEMAIL)
+ && hasPermission(context, Manifest.permission.WRITE_VOICEMAIL));
+ }
+
+ public static boolean hasModifyPhoneStatePermission(Context context) {
+ return isDefaultDialer(context)
+ || hasPermission(context, Manifest.permission.MODIFY_PHONE_STATE);
+ }
+
+ public static boolean hasReadPhoneStatePermission(Context context) {
+ return isDefaultDialer(context) || hasPermission(context, Manifest.permission.READ_PHONE_STATE);
+ }
+
+ public static boolean hasCallPhonePermission(Context context) {
+ return isDefaultDialer(context) || hasPermission(context, Manifest.permission.CALL_PHONE);
+ }
+
+ private static boolean hasPermission(Context context, String permission) {
+ return ContextCompat.checkSelfPermission(context, permission)
+ == PackageManager.PERMISSION_GRANTED;
+ }
+
+ public static boolean isDefaultDialer(Context context) {
+ final boolean result =
+ TextUtils.equals(
+ context.getPackageName(), getTelecomManager(context).getDefaultDialerPackage());
+ if (result) {
+ sWarningLogged = false;
+ } else {
+ if (!sWarningLogged) {
+ // Log only once to prevent spam.
+ Log.w(TAG, "Dialer is not currently set to be default dialer");
+ sWarningLogged = true;
+ }
+ }
+ return result;
+ }
+
+ private static TelecomManager getTelecomManager(Context context) {
+ return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
+ }
+}