API review PhoneManager -> TelecommManager. Rename methods (6/6)

PhoneManager
- handlePinMMI docs should explain what a Pin is and what MMI is
- rename isInAPhoneCall to isInCall
- rename showCallScreen to showInCallScreen
- merge this class into TelecommManager, we don't need both

Bug: 16960458

Change-Id: I7d573e27ed093f2ddb7849703cc62f9916835393
diff --git a/api/current.txt b/api/current.txt
index 7b88073..53a782a 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -7357,7 +7357,6 @@
     field public static final java.lang.String NFC_SERVICE = "nfc";
     field public static final java.lang.String NOTIFICATION_SERVICE = "notification";
     field public static final java.lang.String NSD_SERVICE = "servicediscovery";
-    field public static final java.lang.String PHONE_SERVICE = "phone_service";
     field public static final java.lang.String POWER_SERVICE = "power";
     field public static final java.lang.String PRINT_SERVICE = "print";
     field public static final java.lang.String RESTRICTIONS_SERVICE = "restrictions";
@@ -22774,17 +22773,6 @@
 
 }
 
-package android.phone {
-
-  public final class PhoneManager {
-    method public void cancelMissedCallsNotification();
-    method public boolean handlePinMmi(java.lang.String);
-    method public boolean isInAPhoneCall();
-    method public void showCallScreen(boolean);
-  }
-
-}
-
 package android.preference {
 
   public class CheckBoxPreference extends android.preference.TwoStatePreference {
@@ -28764,12 +28752,16 @@
 
   public class TelecommManager {
     method public void addNewIncomingCall(android.telecomm.PhoneAccountHandle, android.os.Bundle);
+    method public void cancelMissedCallsNotification();
     method public void clearAccounts(java.lang.String);
     method public android.telecomm.PhoneAccountHandle getDefaultOutgoingPhoneAccount();
     method public java.util.List<android.telecomm.PhoneAccountHandle> getEnabledPhoneAccounts();
     method public android.telecomm.PhoneAccount getPhoneAccount(android.telecomm.PhoneAccountHandle);
+    method public boolean handleMmi(java.lang.String);
     method public boolean hasMultipleEnabledAccounts();
+    method public boolean isInCall();
     method public void registerPhoneAccount(android.telecomm.PhoneAccount);
+    method public void showInCallScreen(boolean);
     method public void unregisterPhoneAccount(android.telecomm.PhoneAccountHandle);
     field public static final java.lang.String ACTION_CONNECTION_SERVICE_CONFIGURE = "android.intent.action.CONNECTION_SERVICE_CONFIGURE";
     field public static final java.lang.String ACTION_SHOW_CALL_SETTINGS = "android.telecomm.intent.action.SHOW_CALL_SETTINGS";
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index da343ac..884b046 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -122,7 +122,6 @@
 import android.os.UserManager;
 import android.os.storage.IMountService;
 import android.os.storage.StorageManager;
-import android.phone.PhoneManager;
 import android.print.IPrintManager;
 import android.print.PrintManager;
 import android.service.fingerprint.IFingerprintService;
@@ -570,11 +569,6 @@
                     return new TelecommManager(ctx.getOuterContext());
                 }});
 
-        registerService(PHONE_SERVICE, new ServiceFetcher() {
-                public Object createService(ContextImpl ctx) {
-                    return new PhoneManager(ctx.getOuterContext());
-                }});
-
         registerService(UI_MODE_SERVICE, new ServiceFetcher() {
                 public Object createService(ContextImpl ctx) {
                     return new UiModeManager();
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index a13a928..ebb1f77 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -2203,8 +2203,6 @@
      * @see android.media.MediaRouter
      * @see #TELEPHONY_SERVICE
      * @see android.telephony.TelephonyManager
-     * @see #PHONE_SERVICE
-     * @see android.phone.PhoneManager
      * @see #INPUT_METHOD_SERVICE
      * @see android.view.inputmethod.InputMethodManager
      * @see #UI_MODE_SERVICE
@@ -2558,16 +2556,6 @@
 
     /**
      * Use with {@link #getSystemService} to retrieve a
-     * {@link android.phone.PhoneManager} to manage phone-related features
-     * of the device.
-     *
-     * @see #getSystemService
-     * @see android.phone.PhoneManager
-     */
-    public static final String PHONE_SERVICE = "phone_service";  // "phone" used by telephony.
-
-    /**
-     * Use with {@link #getSystemService} to retrieve a
      * {@link android.text.ClipboardManager} for accessing and modifying
      * the contents of the global clipboard.
      *
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index 6dec036..1ad3620 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -34,8 +34,8 @@
 import android.os.UserHandle;
 import android.os.storage.IMountService;
 import android.os.storage.StorageManager;
-import android.phone.PhoneManager;
 import android.provider.Settings;
+import android.telecomm.TelecommManager;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.IWindowManager;
@@ -1438,7 +1438,7 @@
         }
 
         int textId;
-        if (getPhoneManager().isInAPhoneCall()) {
+        if (getTelecommManager().isInCall()) {
             // show "return to call" text and show phone icon
             textId = R.string.lockscreen_return_to_call;
             int phoneCallIcon = showIcon ? R.drawable.stat_sys_phone_call : 0;
@@ -1456,11 +1456,11 @@
      * on various lockscreens.
      */
     public void resumeCall() {
-        getPhoneManager().showCallScreen(false);
+        getTelecommManager().showInCallScreen(false);
     }
 
-    private PhoneManager getPhoneManager() {
-        return (PhoneManager) mContext.getSystemService(Context.PHONE_SERVICE);
+    private TelecommManager getTelecommManager() {
+        return (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE);
     }
 
     private void finishBiometricWeak() {
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 0af2457..dae539b 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -2912,13 +2912,13 @@
     }
 
     private boolean isInCommunication() {
-        boolean isInAPhoneCall = false;
+        boolean IsInCall = false;
 
         TelecommManager telecommManager =
                 (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE);
-        isInAPhoneCall = telecommManager.isInAPhoneCall();
+        IsInCall = telecommManager.isInCall();
 
-        return (isInAPhoneCall || getMode() == AudioManager.MODE_IN_COMMUNICATION);
+        return (IsInCall || getMode() == AudioManager.MODE_IN_COMMUNICATION);
     }
 
     /**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
index cb2d40a..c0b171a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
@@ -29,7 +29,6 @@
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.os.UserHandle;
-import android.phone.PhoneManager;
 import android.provider.MediaStore;
 import android.telecomm.TelecommManager;
 import android.util.AttributeSet;
@@ -324,13 +323,12 @@
     }
 
     public void launchPhone() {
-        TelecommManager tm = TelecommManager.from(mContext);
-        if (tm.isInAPhoneCall()) {
-            final PhoneManager pm = (PhoneManager) mContext.getSystemService(Context.PHONE_SERVICE);
+        final TelecommManager tm = TelecommManager.from(mContext);
+        if (tm.isInCall()) {
             AsyncTask.execute(new Runnable() {
                 @Override
                 public void run() {
-                    pm.showCallScreen(false /* showDialpad */);
+                    tm.showInCallScreen(false /* showDialpad */);
                 }
             });
         } else {
diff --git a/phone/java/android/phone/PhoneManager.java b/phone/java/android/phone/PhoneManager.java
deleted file mode 100644
index f61b054..0000000
--- a/phone/java/android/phone/PhoneManager.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * 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
- *
- *      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 android.phone;
-
-import android.content.Context;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.util.Log;
-
-import com.android.internal.telecomm.ITelecommService;
-
-/**
- * Exposes call-related functionality for use by phone and dialer apps.
- */
-public final class PhoneManager {
-    private static final String TAG = PhoneManager.class.getSimpleName();
-
-    private final Context mContext;
-
-    /**
-     * @hide
-     */
-    public PhoneManager(Context context) {
-        Context appContext = context.getApplicationContext();
-        if (appContext != null) {
-            mContext = appContext;
-        } else {
-            mContext = context;
-        }
-    }
-
-    /**
-     * Processes the specified dial string as an MMI code.
-     * <p>
-     * Requires that the method-caller be set as the system dialer app.
-     * </p>
-     *
-     * @param dialString The digits to dial.
-     * @return True if the digits were processed as an MMI code, false otherwise.
-     */
-    public boolean handlePinMmi(String dialString) {
-        ITelecommService service = getTelecommService();
-        if (service != null) {
-            try {
-                return service.handlePinMmi(dialString);
-            } catch (RemoteException e) {
-                Log.e(TAG, "Error calling ITelecommService#handlePinMmi", e);
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Removes the missed-call notification if one is present.
-     * <p>
-     * Requires that the method-caller be set as the system dialer app.
-     * </p>
-     */
-    public void cancelMissedCallsNotification() {
-        ITelecommService service = getTelecommService();
-        if (service != null) {
-            try {
-                service.cancelMissedCallsNotification();
-            } catch (RemoteException e) {
-                Log.e(TAG, "Error calling ITelecommService#cancelMissedCallsNotification", e);
-            }
-        }
-    }
-
-    /**
-     * Brings the in-call screen to the foreground if there is an ongoing call. If there is
-     * currently no ongoing call, then this method does nothing.
-     * <p>
-     * Requires that the method-caller be set as the system dialer app or have the
-     * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
-     * </p>
-     *
-     * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
-     */
-    public void showCallScreen(boolean showDialpad) {
-        ITelecommService service = getTelecommService();
-        if (service != null) {
-            try {
-                service.showCallScreen(showDialpad);
-            } catch (RemoteException e) {
-                Log.e(TAG, "Error calling ITelecommService#showCallScreen", e);
-            }
-        }
-    }
-
-    /**
-     * Returns whether there is an ongoing phone call.
-     * <p>
-     * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
-     * </p>
-     */
-    public boolean isInAPhoneCall() {
-        ITelecommService service = getTelecommService();
-        if (service != null) {
-            try {
-                return service.isInAPhoneCall();
-            } catch (RemoteException e) {
-                Log.e(TAG, "Error caling ITelecommService#isInAPhoneCall", e);
-            }
-        }
-        return false;
-    }
-
-    private ITelecommService getTelecommService() {
-        return ITelecommService.Stub.asInterface(
-                ServiceManager.getService(Context.TELECOMM_SERVICE));
-    }
-}
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index 9e268c3..c73d751 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -4266,7 +4266,7 @@
                             result &= ~ACTION_PASS_TO_USER;
                             break;
                         }
-                        if (telecommManager.isInAPhoneCall()
+                        if (telecommManager.isInCall()
                                 && (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.
@@ -4341,7 +4341,7 @@
                             telecommManager.silenceRinger();
                         } else if ((mIncallPowerBehavior
                                 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
-                                && telecommManager.isInAPhoneCall() && interactive) {
+                                && telecommManager.isInCall() && interactive) {
                             // Otherwise, if "Power button ends call" is enabled,
                             // the Power button will hang up any current active call.
                             hungUp = telecommManager.endCall();
@@ -4384,7 +4384,7 @@
                 if (down) {
                     TelecommManager telecommManager = getTelecommService();
                     if (telecommManager != null) {
-                        if (telecommManager.isInAPhoneCall()) {
+                        if (telecommManager.isInCall()) {
                             // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
                             // to avoid music playback.
                             break;
diff --git a/telecomm/java/android/telecomm/TelecommManager.java b/telecomm/java/android/telecomm/TelecommManager.java
index e59fea1..178a25f 100644
--- a/telecomm/java/android/telecomm/TelecommManager.java
+++ b/telecomm/java/android/telecomm/TelecommManager.java
@@ -17,7 +17,6 @@
 import android.annotation.SystemApi;
 import android.content.ComponentName;
 import android.content.Context;
-
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.os.ServiceManager;
@@ -394,14 +393,15 @@
     /**
      * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
      * states).
-     *
-     * @hide
+     * <p>
+     * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
+     * </p>
      */
     @SystemApi
-    public boolean isInAPhoneCall() {
+    public boolean isInCall() {
         try {
             if (isServiceConnected()) {
-                return getTelecommService().isInAPhoneCall();
+                return getTelecommService().isInCall();
             }
         } catch (RemoteException e) {
             Log.e(TAG, "RemoteException attempting to get default phone app.", e);
@@ -541,6 +541,67 @@
         }
     }
 
+    /**
+     * Processes the specified dial string as an MMI code.
+     * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
+     * Some of these sequences launch special behavior through handled by Telephony.
+     * <p>
+     * Requires that the method-caller be set as the system dialer app.
+     * </p>
+     *
+     * @param dialString The digits to dial.
+     * @return True if the digits were processed as an MMI code, false otherwise.
+     */
+    public boolean handleMmi(String dialString) {
+        ITelecommService service = getTelecommService();
+        if (service != null) {
+            try {
+                return service.handlePinMmi(dialString);
+            } catch (RemoteException e) {
+                Log.e(TAG, "Error calling ITelecommService#handlePinMmi", e);
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Removes the missed-call notification if one is present.
+     * <p>
+     * Requires that the method-caller be set as the system dialer app.
+     * </p>
+     */
+    public void cancelMissedCallsNotification() {
+        ITelecommService service = getTelecommService();
+        if (service != null) {
+            try {
+                service.cancelMissedCallsNotification();
+            } catch (RemoteException e) {
+                Log.e(TAG, "Error calling ITelecommService#cancelMissedCallsNotification", e);
+            }
+        }
+    }
+
+    /**
+     * Brings the in-call screen to the foreground if there is an ongoing call. If there is
+     * currently no ongoing call, then this method does nothing.
+     * <p>
+     * Requires that the method-caller be set as the system dialer app or have the
+     * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
+     * </p>
+     *
+     * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
+     */
+    public void showInCallScreen(boolean showDialpad) {
+        ITelecommService service = getTelecommService();
+        if (service != null) {
+            try {
+                service.showInCallScreen(showDialpad);
+            } catch (RemoteException e) {
+                Log.e(TAG, "Error calling ITelecommService#showCallScreen", e);
+            }
+        }
+    }
+
     private ITelecommService getTelecommService() {
         return ITelecommService.Stub.asInterface(ServiceManager.getService(TELECOMM_SERVICE_NAME));
     }
diff --git a/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl b/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl
index 3c1dea6..0ac5078 100644
--- a/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl
+++ b/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl
@@ -32,7 +32,7 @@
      *
      * @param showDialpad if true, make the dialpad visible initially.
      */
-    void showCallScreen(boolean showDialpad);
+    void showInCallScreen(boolean showDialpad);
 
     /**
      * @see TelecommManager#getDefaultOutgoingPhoneAccount
@@ -79,9 +79,9 @@
     void silenceRinger();
 
     /**
-     * @see TelecommManager#isInAPhoneCall
+     * @see TelecommManager#isInCall
      */
-    boolean isInAPhoneCall();
+    boolean isInCall();
 
     /**
      * @see TelecomManager#isRinging
@@ -99,12 +99,12 @@
     void acceptRingingCall();
 
     /**
-     * @see PhoneManager#cancelMissedCallsNotification
+     * @see TelecommManager#cancelMissedCallsNotification
      */
     void cancelMissedCallsNotification();
 
     /**
-     * @see PhoneManager#handlePinMmi
+     * @see TelecommManager#handleMmi
      */
     boolean handlePinMmi(String dialString);