Merge "Revert "Remove the OEM hook implementation and usage"" am: c77e3632f6 am: e6243167d4
am: 13a80521c3

Change-Id: I181efc68689fea72fda85d012059aaddb324b713
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 06153f2..4698f9a 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -168,6 +168,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;
@@ -745,6 +747,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);
@@ -3318,6 +3335,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);