diff options
4 files changed, 169 insertions, 57 deletions
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index d882bc8..628d35b 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -63,6 +63,8 @@ import android.os.UserHandle; import android.os.Vibrator; import android.provider.Settings; import android.provider.Settings.System; + +import android.telecomm.TelecommManager; import android.text.TextUtils; import android.util.Log; import android.view.KeyEvent; @@ -2725,17 +2727,13 @@ public class AudioService extends IAudioService.Stub { } private boolean isInCommunication() { - boolean isOffhook = false; + boolean isInAPhoneCall = false; - if (mVoiceCapable) { - try { - ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); - if (phone != null) isOffhook = phone.isOffhook(); - } catch (RemoteException e) { - Log.w(TAG, "Couldn't connect to phone service", e); - } - } - return (isOffhook || getMode() == AudioManager.MODE_IN_COMMUNICATION); + TelecommManager telecommManager = + (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE); + isInAPhoneCall = telecommManager.isInAPhoneCall(); + + return (isInAPhoneCall || getMode() == AudioManager.MODE_IN_COMMUNICATION); } /** diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index ddfa9c1..95edf07 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -64,7 +64,7 @@ import android.os.Vibrator; import android.provider.Settings; import android.service.dreams.DreamService; import android.service.dreams.IDreamManager; -import android.telephony.TelephonyManager; +import android.telecomm.TelecommManager; import android.util.DisplayMetrics; import android.util.EventLog; import android.util.Log; @@ -2038,8 +2038,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { ServiceManager.checkService(DreamService.DREAM_SERVICE)); } - TelephonyManager getTelephonyService() { - return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); + TelecommManager getTelecommService() { + return (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE); } static IAudioService getAudioService() { @@ -2126,10 +2126,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { } // If an incoming call is ringing, HOME is totally disabled. - // (The user is already on the InCallScreen at this point, + // (The user is already on the InCallUI at this point, // and his ONLY options are to answer or reject the call.) - TelephonyManager telephonyManager = getTelephonyService(); - if (telephonyManager != null && telephonyManager.isRinging()) { + TelecommManager telecommManager = getTelecommService(); + if (telecommManager != null && telecommManager.isRinging()) { Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); return -1; } @@ -4152,9 +4152,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } if (down) { - TelephonyManager telephonyManager = getTelephonyService(); - if (telephonyManager != null) { - if (telephonyManager.isRinging()) { + TelecommManager telecommManager = getTelecommService(); + if (telecommManager != null) { + if (telecommManager.isRinging()) { // If an incoming call is ringing, either VOLUME key means // "silence ringer". We handle these keys here, rather than // in the InCallScreen, to make sure we'll respond to them @@ -4166,14 +4166,14 @@ public class PhoneWindowManager implements WindowManagerPolicy { // Silence the ringer. (It's safe to call this // even if the ringer has already been silenced.) - telephonyManager.silenceRinger(); + telecommManager.silenceRinger(); // And *don't* pass this key thru to the current activity // (which is probably the InCallScreen.) result &= ~ACTION_PASS_TO_USER; break; } - if (telephonyManager.isOffhook() + if (telecommManager.isInAPhoneCall() && (result & ACTION_PASS_TO_USER) == 0) { // If we are in call but we decided not to pass the key to // the application, just pass it to the session service. @@ -4199,10 +4199,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { case KeyEvent.KEYCODE_ENDCALL: { result &= ~ACTION_PASS_TO_USER; if (down) { - TelephonyManager telephonyManager = getTelephonyService(); + TelecommManager telecommManager = getTelecommService(); boolean hungUp = false; - if (telephonyManager != null) { - hungUp = telephonyManager.endCall(); + if (telecommManager != null) { + hungUp = telecommManager.endCall(); } interceptPowerKeyDown(!interactive || hungUp); } else { @@ -4238,19 +4238,19 @@ public class PhoneWindowManager implements WindowManagerPolicy { interceptScreenshotChord(); } - TelephonyManager telephonyManager = getTelephonyService(); + TelecommManager telecommManager = getTelecommService(); boolean hungUp = false; - if (telephonyManager != null) { - if (telephonyManager.isRinging()) { + if (telecommManager != null) { + if (telecommManager.isRinging()) { // Pressing Power while there's a ringing incoming // call should silence the ringer. - telephonyManager.silenceRinger(); + telecommManager.silenceRinger(); } else if ((mIncallPowerBehavior & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 - && telephonyManager.isOffhook() && interactive) { + && telecommManager.isInAPhoneCall() && interactive) { // Otherwise, if "Power button ends call" is enabled, // the Power button will hang up any current active call. - hungUp = telephonyManager.endCall(); + hungUp = telecommManager.endCall(); } } interceptPowerKeyDown(!interactive || hungUp @@ -4286,9 +4286,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { case KeyEvent.KEYCODE_MEDIA_PAUSE: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: if (down) { - TelephonyManager telephonyManager = getTelephonyService(); - if (telephonyManager != null) { - if (!telephonyManager.isIdle()) { + TelecommManager telecommManager = getTelecommService(); + if (telecommManager != null) { + if (telecommManager.isInAPhoneCall()) { // Suppress PLAY/PAUSE toggle when phone is ringing or in-call // to avoid music playback. break; @@ -4321,12 +4321,12 @@ public class PhoneWindowManager implements WindowManagerPolicy { case KeyEvent.KEYCODE_CALL: { if (down) { - TelephonyManager telephonyManager = getTelephonyService(); - if (telephonyManager != null) { - if (telephonyManager.isRinging()) { + TelecommManager telecommManager = getTelecommService(); + if (telecommManager != null) { + if (telecommManager.isRinging()) { Log.i(TAG, "interceptKeyBeforeQueueing:" + " CALL key-down while ringing: Answer the call!"); - telephonyManager.answerRingingCall(); + telecommManager.acceptRingingCall(); // And *don't* pass this key thru to the current activity // (which is presumably the InCallScreen.) diff --git a/telecomm/java/android/telecomm/TelecommManager.java b/telecomm/java/android/telecomm/TelecommManager.java index a0abc28..6bb75be 100644 --- a/telecomm/java/android/telecomm/TelecommManager.java +++ b/telecomm/java/android/telecomm/TelecommManager.java @@ -1,17 +1,15 @@ /* * Copyright (C) 2014 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 + * 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 + * 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. + * 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 android.telecomm; @@ -62,14 +60,111 @@ public class TelecommManager { @SystemApi public ComponentName getDefaultPhoneApp() { try { - return getTelecommService().getDefaultPhoneApp(); + if (isServiceConnected()) { + return getTelecommService().getDefaultPhoneApp(); + } } catch (RemoteException e) { Log.e(TAG, "RemoteException attempting to get the default phone app.", e); } return null; } + /** + * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding + * states). + * + * @hide + */ + @SystemApi + public boolean isInAPhoneCall() { + try { + if (isServiceConnected()) { + return getTelecommService().isInAPhoneCall(); + } + } catch (RemoteException e) { + Log.e(TAG, "RemoteException attempting to get default phone app.", e); + } + return false; + } + + /** + * Returns whether there currently exists is a ringing incoming-call. + * + * @hide + */ + @SystemApi + public boolean isRinging() { + try { + if (isServiceConnected()) { + return getTelecommService().isRinging(); + } + } catch (RemoteException e) { + Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e); + } + return false; + } + + /** + * Ends an ongoing call. TODO(santoscordon): L-release - need to convert all invocations of + * ITelephony#endCall to use this method (clockwork & gearhead). + * + * @hide + */ + @SystemApi + public boolean endCall() { + try { + if (isServiceConnected()) { + return getTelecommService().endCall(); + } + } catch (RemoteException e) { + Log.e(TAG, "Error calling ITelecommService#endCall", e); + } + return false; + } + + /** + * If there is a ringing incoming call, this method accepts the call on behalf of the user. + * TODO(santoscordon): L-release - need to convert all invocation of + * ITelephony#answerRingingCall to use this method (clockwork & gearhead). + * + * @hide + */ + @SystemApi + public void acceptRingingCall() { + try { + if (isServiceConnected()) { + getTelecommService().acceptRingingCall(); + } + } catch (RemoteException e) { + Log.e(TAG, "Error calling ITelecommService#acceptRingingCall", e); + } + } + + /** + * Silences the ringer if a ringing call exists. + * + * @hide + */ + @SystemApi + public void silenceRinger() { + try { + if (isServiceConnected()) { + getTelecommService().silenceRinger(); + } + } catch (RemoteException e) { + Log.e(TAG, "Error calling ITelecommService#silenceRinger", e); + } + } + private ITelecommService getTelecommService() { return ITelecommService.Stub.asInterface(ServiceManager.getService(TELECOMM_SERVICE_NAME)); } + + private boolean isServiceConnected() { + boolean isConnected = getTelecommService() != null; + if (!isConnected) { + Log.w(TAG, "Telecomm Service not found."); + } + return isConnected; + } } diff --git a/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl b/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl index 2ae5768..65389df 100644 --- a/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl +++ b/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl @@ -25,16 +25,6 @@ import android.telecomm.Subscription; * {@hide} */ interface ITelecommService { - - /** - * Silence the ringer if an incoming call is currently ringing. - * (If vibrating, stop the vibrator also.) - * - * It's safe to call this if the ringer has already been silenced, or - * even if there's no incoming call. (If so, this method will do nothing.) - */ - void silenceRinger(); - /** * Brings the in-call screen to the foreground if there is an active call. * @@ -61,4 +51,33 @@ interface ITelecommService { * Returns the component name of the default phone application. */ ComponentName getDefaultPhoneApp(); + + // + // Internal system apis relating to call management. + // + + /** + * @see TelecommManager#silenceRinger + */ + void silenceRinger(); + + /** + * @see TelecommManager#isInAPhoneCall + */ + boolean isInAPhoneCall(); + + /** + * @see TelecomManager#isRinging + */ + boolean isRinging(); + + /** + * @see TelecommManager#endCall + */ + boolean endCall(); + + /** + * @see TelecommManager#acceptRingingCall + */ + void acceptRingingCall(); } |