Restore the OEM hook implementation and usage

The current plan is to keep the OEM hook implementation in the 
framework, this is for legacy device and old device upgrading 
(per b/78098059).

For P launching device, the OEM hook service is removed in hal, 
so the OEM hook api in framework should return something dummy, and 
prevent infinite loop to get service, but these parts should be done
in seperate CLs after this restore CL is merged.

This reverts commit baafa294d1b1fc4067b334851ec62564537bc6fa.

Bug: 34344851
Change-Id: I6e49d2b34c5f34f59d7cae1fc20b3881ee677642
Test: pass Treehugger tests; pass cuttlefish test RilE2eTests

Mergde-In: I8310e985ca805fcda519f5aac2b7c767aac1f4c6
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index d3dd93c..7493858 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -156,6 +156,8 @@
     private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
     private static final int CMD_SEND_ENVELOPE = 25;
     private static final int EVENT_SEND_ENVELOPE_DONE = 26;
+    private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
+    private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
     private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
     private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
     private static final int CMD_EXCHANGE_SIM_IO = 31;
@@ -721,6 +723,21 @@
                     handleNullReturnEvent(msg, "setPreferredNetworkType");
                     break;
 
+                case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
+                    request = (MainThreadRequest)msg.obj;
+                    onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
+                    mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
+                    break;
+
+                case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
+                    ar = (AsyncResult)msg.obj;
+                    request = (MainThreadRequest)ar.userObj;
+                    request.result = ar;
+                    synchronized (request) {
+                        request.notifyAll();
+                    }
+                    break;
+
                 case CMD_SET_VOICEMAIL_NUMBER:
                     request = (MainThreadRequest) msg.obj;
                     onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
@@ -3135,6 +3152,39 @@
     }
 
     @Override
+    @Deprecated
+    public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
+        enforceModifyPermission();
+
+        int returnValue = 0;
+        try {
+            AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
+            if(result.exception == null) {
+                if (result.result != null) {
+                    byte[] responseData = (byte[])(result.result);
+                    if(responseData.length > oemResp.length) {
+                        Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
+                                responseData.length +  "bytes. Buffer Size is " +
+                                oemResp.length + "bytes.");
+                    }
+                    System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
+                    returnValue = responseData.length;
+                }
+            } else {
+                CommandException ex = (CommandException) result.exception;
+                returnValue = ex.getCommandError().ordinal();
+                if(returnValue > 0) returnValue *= -1;
+            }
+        } catch (RuntimeException e) {
+            Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
+            returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
+            if(returnValue > 0) returnValue *= -1;
+        }
+
+        return returnValue;
+    }
+
+    @Override
     public void setRadioCapability(RadioAccessFamily[] rafs) {
         try {
             ProxyController.getInstance().setRadioCapability(rafs);