DO NOT MERGE Check PAH in addNewIncomingCall

Check to be sure that the PhoneAccountHandle in addNewIncomingCall
corresponds to an existing registered PhoneAccount in Telecom and that
the PhoneAccount is enabled. Otherwise, throw a SecurityException.

Bug: 26864502
Change-Id: I6bbd8a1ece821b62bee2c94decde87a41afbf8b0
diff --git a/src/com/android/server/telecom/TelecomServiceImpl.java b/src/com/android/server/telecom/TelecomServiceImpl.java
index bb999c7..9a04ad6 100644
--- a/src/com/android/server/telecom/TelecomServiceImpl.java
+++ b/src/com/android/server/telecom/TelecomServiceImpl.java
@@ -44,6 +44,7 @@
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
+import android.util.EventLog;
 
 // TODO: Needed for move to system service: import com.android.internal.R;
 import com.android.internal.telecom.ITelecomService;
@@ -766,6 +767,7 @@
                                 phoneAccountHandle.getComponentName().getPackageName());
                         // Make sure it doesn't cross the UserHandle boundary
                         enforceUserHandleMatchesCaller(phoneAccountHandle);
+                        enforcePhoneAccountIsRegisteredEnabled(phoneAccountHandle);
                     }
 
                     long token = Binder.clearCallingIdentity();
@@ -801,6 +803,7 @@
 
                     // Make sure it doesn't cross the UserHandle boundary
                     enforceUserHandleMatchesCaller(phoneAccountHandle);
+                    enforcePhoneAccountIsRegisteredEnabled(phoneAccountHandle);
                     long token = Binder.clearCallingIdentity();
 
                     try {
@@ -1080,6 +1083,21 @@
         return false;
     }
 
+    // Enforce that the PhoneAccountHandle being passed in is both registered to the current user
+    // and enabled.
+    private void enforcePhoneAccountIsRegisteredEnabled(PhoneAccountHandle phoneAccountHandle) {
+        PhoneAccount phoneAccount = mPhoneAccountRegistrar.getPhoneAccountCheckCallingUser(
+                phoneAccountHandle);
+        if (phoneAccount == null) {
+            EventLog.writeEvent(0x534e4554, "26864502", Binder.getCallingUid(), "R");
+            throw new SecurityException("This PhoneAccountHandle is not registered for this user!");
+        }
+        if (!phoneAccount.isEnabled()) {
+            EventLog.writeEvent(0x534e4554, "26864502", Binder.getCallingUid(), "E");
+            throw new SecurityException("This PhoneAccountHandle is not enabled for this user!");
+        }
+    }
+
     private void enforcePhoneAccountModificationForPackage(String packageName) {
         // TODO: Use a new telecomm permission for this instead of reusing modify.