From 39eeda8cf081e9f5335955dd7d6543041925e22e Mon Sep 17 00:00:00 2001 From: erfanian Date: Mon, 7 Aug 2017 14:22:36 -0700 Subject: Move TelphonyManagerCompat outside of contacts/common. This class will be used for Assisted Dialing. #turndowncontactscommon Bug: 64205446,37208802 Test: TAP PiperOrigin-RevId: 164510740 Change-Id: I5dec67d2182b33bf2057953aab69e3b561af5708 --- .../common/compat/TelephonyManagerCompat.java | 183 --------------------- .../android/dialer/app/SpecialCharSequenceMgr.java | 2 +- .../app/settings/DialerSettingsActivity.java | 2 +- .../error/VoicemailStatusCorruptionHandler.java | 2 +- .../error/VoicemailTosMessageCreator.java | 2 +- .../compat/telephony/TelephonyManagerCompat.java | 183 +++++++++++++++++++++ java/com/android/incallui/call/DialerCall.java | 2 +- 7 files changed, 188 insertions(+), 188 deletions(-) delete mode 100644 java/com/android/contacts/common/compat/TelephonyManagerCompat.java create mode 100644 java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java (limited to 'java/com/android') diff --git a/java/com/android/contacts/common/compat/TelephonyManagerCompat.java b/java/com/android/contacts/common/compat/TelephonyManagerCompat.java deleted file mode 100644 index b428908cd..000000000 --- a/java/com/android/contacts/common/compat/TelephonyManagerCompat.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * 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.contacts.common.compat; - -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build.VERSION; -import android.os.Build.VERSION_CODES; -import android.support.annotation.Nullable; -import android.support.v4.os.BuildCompat; -import android.telecom.PhoneAccountHandle; -import android.telephony.TelephonyManager; -import com.android.dialer.common.Assert; -import com.android.dialer.common.LogUtil; -import com.android.dialer.telecom.TelecomUtil; -import java.lang.reflect.InvocationTargetException; - -public class TelephonyManagerCompat { - - // TODO(maxwelb): Use public API for these constants when available - public static final String EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE = - "android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE"; - public static final String EVENT_HANDOVER_TO_WIFI_FAILED = - "android.telephony.event.EVENT_HANDOVER_TO_WIFI_FAILED"; - public static final String EVENT_CALL_REMOTELY_HELD = "android.telecom.event.CALL_REMOTELY_HELD"; - public static final String EVENT_CALL_REMOTELY_UNHELD = - "android.telecom.event.CALL_REMOTELY_UNHELD"; - public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START"; - public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE"; - - public static final String EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC = - "android.telephony.event.EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC"; - - public static final String TELEPHONY_MANAGER_CLASS = "android.telephony.TelephonyManager"; - - private static final String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE"; - - /** - * Returns the number of phones available. Returns 1 for Single standby mode (Single SIM - * functionality) Returns 2 for Dual standby mode.(Dual SIM functionality) - * - *

Returns 1 if the method or telephonyManager is not available. - * - * @param telephonyManager The telephony manager instance to use for method calls. - */ - public static int getPhoneCount(@Nullable TelephonyManager telephonyManager) { - if (telephonyManager == null) { - return 1; - } - return telephonyManager.getPhoneCount(); - } - - /** - * Whether the phone supports TTY mode. - * - * @param telephonyManager The telephony manager instance to use for method calls. - * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. - */ - public static boolean isTtyModeSupported(@Nullable TelephonyManager telephonyManager) { - return telephonyManager != null && telephonyManager.isTtyModeSupported(); - } - - /** - * Whether the phone supports hearing aid compatibility. - * - * @param telephonyManager The telephony manager instance to use for method calls. - * @return {@code true} if the device supports hearing aid compatibility, and {@code false} - * otherwise. - */ - public static boolean isHearingAidCompatibilitySupported( - @Nullable TelephonyManager telephonyManager) { - return telephonyManager != null && telephonyManager.isHearingAidCompatibilitySupported(); - } - - /** - * Returns the URI for the per-account voicemail ringtone set in Phone settings. - * - * @param telephonyManager The telephony manager instance to use for method calls. - * @param accountHandle The handle for the {@link android.telecom.PhoneAccount} for which to - * retrieve the voicemail ringtone. - * @return The URI for the ringtone to play when receiving a voicemail from a specific - * PhoneAccount. - */ - @Nullable - public static Uri getVoicemailRingtoneUri( - TelephonyManager telephonyManager, PhoneAccountHandle accountHandle) { - if (VERSION.SDK_INT < VERSION_CODES.N) { - return null; - } - return telephonyManager.getVoicemailRingtoneUri(accountHandle); - } - - /** - * Returns whether vibration is set for voicemail notification in Phone settings. - * - * @param telephonyManager The telephony manager instance to use for method calls. - * @param accountHandle The handle for the {@link android.telecom.PhoneAccount} for which to - * retrieve the voicemail vibration setting. - * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. - */ - public static boolean isVoicemailVibrationEnabled( - TelephonyManager telephonyManager, PhoneAccountHandle accountHandle) { - return VERSION.SDK_INT < VERSION_CODES.N - || telephonyManager.isVoicemailVibrationEnabled(accountHandle); - } - - /** - * This method uses a new system API to enable or disable visual voicemail. TODO(twyen): restrict - * to N MR1, not needed in future SDK. - */ - public static void setVisualVoicemailEnabled( - TelephonyManager telephonyManager, PhoneAccountHandle handle, boolean enabled) { - if (VERSION.SDK_INT < VERSION_CODES.N_MR1) { - Assert.fail("setVisualVoicemailEnabled called on pre-NMR1"); - } - try { - TelephonyManager.class - .getMethod("setVisualVoicemailEnabled", PhoneAccountHandle.class, boolean.class) - .invoke(telephonyManager, handle, enabled); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - LogUtil.e("TelephonyManagerCompat.setVisualVoicemailEnabled", "failed", e); - } - } - - /** - * This method uses a new system API to check if visual voicemail is enabled TODO(twyen): restrict - * to N MR1, not needed in future SDK. - */ - public static boolean isVisualVoicemailEnabled( - TelephonyManager telephonyManager, PhoneAccountHandle handle) { - if (VERSION.SDK_INT < VERSION_CODES.N_MR1) { - Assert.fail("isVisualVoicemailEnabled called on pre-NMR1"); - } - try { - return (boolean) - TelephonyManager.class - .getMethod("isVisualVoicemailEnabled", PhoneAccountHandle.class) - .invoke(telephonyManager, handle); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - LogUtil.e("TelephonyManagerCompat.setVisualVoicemailEnabled", "failed", e); - } - return false; - } - - /** - * Handles secret codes to launch arbitrary activities. - * - * @param context the context to use - * @param secretCode the secret code without the "*#*#" prefix and "#*#*" suffix - */ - public static void handleSecretCode(Context context, String secretCode) { - // Must use system service on O+ to avoid using broadcasts, which are not allowed on O+. - if (BuildCompat.isAtLeastO()) { - if (!TelecomUtil.isDefaultDialer(context)) { - LogUtil.e( - "TelephonyManagerCompat.handleSecretCode", - "not default dialer, cannot send special code"); - return; - } - context.getSystemService(TelephonyManager.class).sendDialerSpecialCode(secretCode); - } else { - // System service call is not supported pre-O, so must use a broadcast for N-. - Intent intent = - new Intent(SECRET_CODE_ACTION, Uri.parse("android_secret_code://" + secretCode)); - context.sendBroadcast(intent); - } - } -} diff --git a/java/com/android/dialer/app/SpecialCharSequenceMgr.java b/java/com/android/dialer/app/SpecialCharSequenceMgr.java index 20222d68c..fd67f4704 100644 --- a/java/com/android/dialer/app/SpecialCharSequenceMgr.java +++ b/java/com/android/dialer/app/SpecialCharSequenceMgr.java @@ -39,7 +39,6 @@ import android.view.WindowManager; import android.widget.EditText; import android.widget.Toast; import com.android.common.io.MoreCloseables; -import com.android.contacts.common.compat.TelephonyManagerCompat; import com.android.contacts.common.database.NoNullCursorAsyncQueryHandler; import com.android.contacts.common.util.ContactDisplayUtils; import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment; @@ -47,6 +46,7 @@ import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.Selec import com.android.dialer.calllogutils.PhoneAccountUtils; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; +import com.android.dialer.compat.telephony.TelephonyManagerCompat; import com.android.dialer.oem.MotorolaUtils; import com.android.dialer.telecom.TelecomUtil; import java.util.ArrayList; diff --git a/java/com/android/dialer/app/settings/DialerSettingsActivity.java b/java/com/android/dialer/app/settings/DialerSettingsActivity.java index 6036c85ce..6010f92b5 100644 --- a/java/com/android/dialer/app/settings/DialerSettingsActivity.java +++ b/java/com/android/dialer/app/settings/DialerSettingsActivity.java @@ -31,11 +31,11 @@ import android.telecom.TelecomManager; import android.telephony.TelephonyManager; import android.view.MenuItem; import android.widget.Toast; -import com.android.contacts.common.compat.TelephonyManagerCompat; import com.android.dialer.about.AboutPhoneFragment; import com.android.dialer.app.R; import com.android.dialer.blocking.FilteredNumberCompat; import com.android.dialer.common.LogUtil; +import com.android.dialer.compat.telephony.TelephonyManagerCompat; import com.android.dialer.proguard.UsedByReflection; import com.android.voicemail.VoicemailClient; import com.android.voicemail.VoicemailComponent; diff --git a/java/com/android/dialer/app/voicemail/error/VoicemailStatusCorruptionHandler.java b/java/com/android/dialer/app/voicemail/error/VoicemailStatusCorruptionHandler.java index 3a169e41c..fa637f355 100644 --- a/java/com/android/dialer/app/voicemail/error/VoicemailStatusCorruptionHandler.java +++ b/java/com/android/dialer/app/voicemail/error/VoicemailStatusCorruptionHandler.java @@ -24,9 +24,9 @@ import android.os.Build.VERSION_CODES; import android.provider.VoicemailContract.Status; import android.telecom.PhoneAccountHandle; import android.telephony.TelephonyManager; -import com.android.contacts.common.compat.TelephonyManagerCompat; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; +import com.android.dialer.compat.telephony.TelephonyManagerCompat; import com.android.dialer.configprovider.ConfigProviderBindings; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; diff --git a/java/com/android/dialer/app/voicemail/error/VoicemailTosMessageCreator.java b/java/com/android/dialer/app/voicemail/error/VoicemailTosMessageCreator.java index 02b2a64aa..865d2527a 100644 --- a/java/com/android/dialer/app/voicemail/error/VoicemailTosMessageCreator.java +++ b/java/com/android/dialer/app/voicemail/error/VoicemailTosMessageCreator.java @@ -31,9 +31,9 @@ import android.text.SpannableString; import android.text.style.StyleSpan; import android.view.View; import android.view.View.OnClickListener; -import com.android.contacts.common.compat.TelephonyManagerCompat; import com.android.dialer.app.voicemail.error.VoicemailErrorMessage.Action; import com.android.dialer.common.LogUtil; +import com.android.dialer.compat.telephony.TelephonyManagerCompat; import com.android.dialer.configprovider.ConfigProviderBindings; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; diff --git a/java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java b/java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java new file mode 100644 index 000000000..cea137c77 --- /dev/null +++ b/java/com/android/dialer/compat/telephony/TelephonyManagerCompat.java @@ -0,0 +1,183 @@ +/* + * 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.compat.telephony; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; +import android.support.annotation.Nullable; +import android.support.v4.os.BuildCompat; +import android.telecom.PhoneAccountHandle; +import android.telephony.TelephonyManager; +import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; +import com.android.dialer.telecom.TelecomUtil; +import java.lang.reflect.InvocationTargetException; + +public class TelephonyManagerCompat { + + // TODO(maxwelb): Use public API for these constants when available + public static final String EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE = + "android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE"; + public static final String EVENT_HANDOVER_TO_WIFI_FAILED = + "android.telephony.event.EVENT_HANDOVER_TO_WIFI_FAILED"; + public static final String EVENT_CALL_REMOTELY_HELD = "android.telecom.event.CALL_REMOTELY_HELD"; + public static final String EVENT_CALL_REMOTELY_UNHELD = + "android.telecom.event.CALL_REMOTELY_UNHELD"; + public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START"; + public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE"; + + public static final String EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC = + "android.telephony.event.EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC"; + + public static final String TELEPHONY_MANAGER_CLASS = "android.telephony.TelephonyManager"; + + private static final String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE"; + + /** + * Returns the number of phones available. Returns 1 for Single standby mode (Single SIM + * functionality) Returns 2 for Dual standby mode.(Dual SIM functionality) + * + *

Returns 1 if the method or telephonyManager is not available. + * + * @param telephonyManager The telephony manager instance to use for method calls. + */ + public static int getPhoneCount(@Nullable TelephonyManager telephonyManager) { + if (telephonyManager == null) { + return 1; + } + return telephonyManager.getPhoneCount(); + } + + /** + * Whether the phone supports TTY mode. + * + * @param telephonyManager The telephony manager instance to use for method calls. + * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. + */ + public static boolean isTtyModeSupported(@Nullable TelephonyManager telephonyManager) { + return telephonyManager != null && telephonyManager.isTtyModeSupported(); + } + + /** + * Whether the phone supports hearing aid compatibility. + * + * @param telephonyManager The telephony manager instance to use for method calls. + * @return {@code true} if the device supports hearing aid compatibility, and {@code false} + * otherwise. + */ + public static boolean isHearingAidCompatibilitySupported( + @Nullable TelephonyManager telephonyManager) { + return telephonyManager != null && telephonyManager.isHearingAidCompatibilitySupported(); + } + + /** + * Returns the URI for the per-account voicemail ringtone set in Phone settings. + * + * @param telephonyManager The telephony manager instance to use for method calls. + * @param accountHandle The handle for the {@link android.telecom.PhoneAccount} for which to + * retrieve the voicemail ringtone. + * @return The URI for the ringtone to play when receiving a voicemail from a specific + * PhoneAccount. + */ + @Nullable + public static Uri getVoicemailRingtoneUri( + TelephonyManager telephonyManager, PhoneAccountHandle accountHandle) { + if (VERSION.SDK_INT < VERSION_CODES.N) { + return null; + } + return telephonyManager.getVoicemailRingtoneUri(accountHandle); + } + + /** + * Returns whether vibration is set for voicemail notification in Phone settings. + * + * @param telephonyManager The telephony manager instance to use for method calls. + * @param accountHandle The handle for the {@link android.telecom.PhoneAccount} for which to + * retrieve the voicemail vibration setting. + * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. + */ + public static boolean isVoicemailVibrationEnabled( + TelephonyManager telephonyManager, PhoneAccountHandle accountHandle) { + return VERSION.SDK_INT < VERSION_CODES.N + || telephonyManager.isVoicemailVibrationEnabled(accountHandle); + } + + /** + * This method uses a new system API to enable or disable visual voicemail. TODO(twyen): restrict + * to N MR1, not needed in future SDK. + */ + public static void setVisualVoicemailEnabled( + TelephonyManager telephonyManager, PhoneAccountHandle handle, boolean enabled) { + if (VERSION.SDK_INT < VERSION_CODES.N_MR1) { + Assert.fail("setVisualVoicemailEnabled called on pre-NMR1"); + } + try { + TelephonyManager.class + .getMethod("setVisualVoicemailEnabled", PhoneAccountHandle.class, boolean.class) + .invoke(telephonyManager, handle, enabled); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + LogUtil.e("TelephonyManagerCompat.setVisualVoicemailEnabled", "failed", e); + } + } + + /** + * This method uses a new system API to check if visual voicemail is enabled TODO(twyen): restrict + * to N MR1, not needed in future SDK. + */ + public static boolean isVisualVoicemailEnabled( + TelephonyManager telephonyManager, PhoneAccountHandle handle) { + if (VERSION.SDK_INT < VERSION_CODES.N_MR1) { + Assert.fail("isVisualVoicemailEnabled called on pre-NMR1"); + } + try { + return (boolean) + TelephonyManager.class + .getMethod("isVisualVoicemailEnabled", PhoneAccountHandle.class) + .invoke(telephonyManager, handle); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + LogUtil.e("TelephonyManagerCompat.setVisualVoicemailEnabled", "failed", e); + } + return false; + } + + /** + * Handles secret codes to launch arbitrary activities. + * + * @param context the context to use + * @param secretCode the secret code without the "*#*#" prefix and "#*#*" suffix + */ + public static void handleSecretCode(Context context, String secretCode) { + // Must use system service on O+ to avoid using broadcasts, which are not allowed on O+. + if (BuildCompat.isAtLeastO()) { + if (!TelecomUtil.isDefaultDialer(context)) { + LogUtil.e( + "TelephonyManagerCompat.handleSecretCode", + "not default dialer, cannot send special code"); + return; + } + context.getSystemService(TelephonyManager.class).sendDialerSpecialCode(secretCode); + } else { + // System service call is not supported pre-O, so must use a broadcast for N-. + Intent intent = + new Intent(SECRET_CODE_ACTION, Uri.parse("android_secret_code://" + secretCode)); + context.sendBroadcast(intent); + } + } +} diff --git a/java/com/android/incallui/call/DialerCall.java b/java/com/android/incallui/call/DialerCall.java index 6ba0c8121..7ef8ad270 100644 --- a/java/com/android/incallui/call/DialerCall.java +++ b/java/com/android/incallui/call/DialerCall.java @@ -41,13 +41,13 @@ import android.telecom.VideoProfile; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import com.android.contacts.common.compat.CallCompat; -import com.android.contacts.common.compat.TelephonyManagerCompat; import com.android.contacts.common.compat.telecom.TelecomManagerCompat; import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.callintent.CallIntentParser; import com.android.dialer.callintent.CallSpecificAppData; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; +import com.android.dialer.compat.telephony.TelephonyManagerCompat; import com.android.dialer.configprovider.ConfigProviderBindings; import com.android.dialer.enrichedcall.EnrichedCallCapabilities; import com.android.dialer.enrichedcall.EnrichedCallComponent; -- cgit v1.2.3