Get rid of call enum.

Bug: 31758541
Test: hidl_test, hardware/interfaces mma, manual inspection of output
files

Change-Id: I16c076dbff9b0b8688e2492b0b9c97e9f6d48943
diff --git a/Interface.cpp b/Interface.cpp
index cd9dcd3..4d22c5c 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -31,6 +31,26 @@
 }
 
 void Interface::addMethod(Method *method) {
+    /* It is very important that these values NEVER change. These values
+     * must remain unchanged over the lifetime of android. This is
+     * because the framework on a device will be updated independently of
+     * the hals on a device. If the hals are compiled with one set of
+     * transaction values, and the framework with another, then the
+     * interface between them will be destroyed, and the device will not
+     * work.
+     */
+    size_t serial = 1; // hardware::IBinder::FIRST_CALL_TRANSACTION;
+
+    serial += methods().size();
+
+    const Interface *ancestor = mSuperType;
+    while (ancestor != nullptr) {
+        serial += ancestor->methods().size();
+        ancestor = ancestor->superType();
+    }
+
+    method->setSerialId(serial);
+
     mMethods.push_back(method);
 }
 
diff --git a/Method.cpp b/Method.cpp
index 7d7717a..95a688a 100644
--- a/Method.cpp
+++ b/Method.cpp
@@ -52,6 +52,14 @@
     return *mAnnotations;
 }
 
+void Method::setSerialId(size_t serial) {
+    mSerial = serial;
+}
+
+size_t Method::getSerialId() const {
+    return mSerial;
+}
+
 void Method::generateCppSignature(Formatter &out,
                                   const std::string &className,
                                   bool specifyNamespaces) const {
diff --git a/Method.h b/Method.h
index aba7755..3c84914 100644
--- a/Method.h
+++ b/Method.h
@@ -43,6 +43,9 @@
     bool isOneway() const { return mOneway; }
     const std::vector<Annotation *> &annotations() const;
 
+    void setSerialId(size_t serial);
+    size_t getSerialId() const;
+
     void generateCppSignature(Formatter &out,
                               const std::string &className,
                               bool specifyNamespaces) const;
@@ -59,6 +62,7 @@
 
 private:
     std::string mName;
+    size_t mSerial = 0;
     std::vector<TypedVar *> *mArgs;
     std::vector<TypedVar *> *mResults;
     bool mOneway;
diff --git a/generateCpp.cpp b/generateCpp.cpp
index f8a5b1a..7ec8e7f 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -24,7 +24,6 @@
 #include "Scope.h"
 
 #include <algorithm>
-#include <hidl-util/StringHelper.h>
 #include <hidl-util/Formatter.h>
 #include <android-base/logging.h>
 #include <string>
@@ -369,35 +368,6 @@
 
     out << "DECLARE_HWBINDER_META_INTERFACE(" << baseName << ");\n\n";
 
-    out << "enum Call {\n";
-    out.indent();
-
-    bool first = true;
-    for (const auto &method : iface->methods()) {
-        out << StringHelper::Uppercase(method->name());
-
-        if (first) {
-            out << " = ";
-            if (superType != NULL) {
-                out << superType->fqName().cppNamespace()
-                    << "::IHw"
-                    << superType->getBaseName()
-                    << "::Call::CallCount";
-            } else {
-                out << "::android::hardware::IBinder::FIRST_CALL_TRANSACTION";
-            }
-
-            first = false;
-        }
-
-        out << ",\n";
-    }
-
-    out << "CallCount\n";
-
-    out.unindent();
-    out << "};\n\n";
-
     out.unindent();
 
     out << "};\n\n";
@@ -1046,12 +1016,11 @@
             }
 
             out << "_hidl_err = remote()->transact("
-                      << superInterface->fqName().cppNamespace()
-                      << "::IHw"
-                      << superInterface->getBaseName()
-                      << "::Call::"
-                      << StringHelper::Uppercase(method->name())
-                      << ", _hidl_data, &_hidl_reply";
+                << method->getSerialId()
+                << " /* "
+                << method->name()
+                << " */, _hidl_data, &_hidl_reply";
+
             if (method->isOneway()) {
                 out << ", ::android::hardware::IBinder::FLAG_ONEWAY";
             }
@@ -1212,12 +1181,10 @@
 
         for (const auto &method : superInterface->methods()) {
             out << "case "
-                << superInterface->fqName().cppNamespace()
-                << "::IHw"
-                << superInterface->getBaseName()
-                << "::Call::"
-                << StringHelper::Uppercase(method->name())
-                << ":\n{\n";
+                << method->getSerialId()
+                << " /* "
+                << method->name()
+                << " */:\n{\n";
 
             out.indent();
 
diff --git a/generateJava.cpp b/generateJava.cpp
index e9958b6..1e0c478 100644
--- a/generateJava.cpp
+++ b/generateJava.cpp
@@ -21,7 +21,6 @@
 #include "Method.h"
 #include "Scope.h"
 
-#include <hidl-util/StringHelper.h>
 #include <hidl-util/Formatter.h>
 #include <android-base/logging.h>
 
@@ -223,36 +222,6 @@
         return err;
     }
 
-    const std::string base = (superType != NULL)
-        ? (superType->fullJavaName() + ".kOpEnd")
-        : "IHwBinder.FIRST_CALL_TRANSACTION";
-
-    bool first = true;
-    size_t index = 0;
-    for (const auto &method : iface->methods()) {
-        out << "public static final int kOp_"
-            << StringHelper::Uppercase(method->name())
-            << " = "
-            << base;
-
-        if (!first) {
-            out << " + " << index;
-        }
-
-        out << ";\n";
-
-        ++index;
-        first = false;
-    }
-
-    out << "public static final int kOpEnd = "
-        << base
-        << " + "
-        << index
-        << ";";
-
-    out << "\n\n";
-
     for (const auto &method : iface->methods()) {
         const bool returnsValue = !method->results().empty();
         const bool needsCallback = method->results().size() > 1;
@@ -373,9 +342,11 @@
             }
 
             out << "\nHwParcel reply = new HwParcel();\n"
-                << "mRemote.transact(kOp_"
-                << StringHelper::Uppercase(method->name())
-                << ", request, reply, ";
+                << "mRemote.transact("
+                << method->getSerialId()
+                << " /* "
+                << method->name()
+                << " */, request, reply, ";
 
             if (method->isOneway()) {
                 out << "IHwBinder.FLAG_ONEWAY";
@@ -476,11 +447,10 @@
             const bool needsCallback = method->results().size() > 1;
 
             out << "case "
-                << superInterface->fullJavaName()
-                << ".kOp_"
-                <<
-                StringHelper::Uppercase(method->name())
-                << ":\n{\n";
+                << method->getSerialId()
+                << " /* "
+                << method->name()
+                << " */:\n{\n";
 
             out.indent();
 
diff --git a/test/main.cpp b/test/main.cpp
index 88a6ee8..338eaf9 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -569,6 +569,7 @@
 
 struct Bar : public IBar {
     Return<void> doThis(float param) override;
+    Return<void> doThis(uint32_t param) override;
 
     Return<int32_t> doThatAndReturnSomething(int64_t param) override;
 
@@ -635,6 +636,11 @@
     return Void();
 }
 
+Return<void> Bar::doThis(uint32_t param) {
+    ALOGI("SERVER(Bar) doThis (int) (%d)", param);
+    return Void();
+}
+
 Return<int32_t> Bar::doThatAndReturnSomething(
         int64_t param) {
     LOG(INFO) << "SERVER(Bar) doThatAndReturnSomething(" << param << ")";
@@ -1124,6 +1130,13 @@
     EXPECT_EQ(true, true);
 }
 
+TEST_F(HidlTest, FooDoThisIntTest) {
+    ALOGI("CLIENT call doThis (int).");
+    EXPECT_OK(foo->doThis(42u));
+    ALOGI("CLIENT doThis (int) returned.");
+    EXPECT_EQ(true, true);
+}
+
 TEST_F(HidlTest, FooDoThatAndReturnSomethingTest) {
     ALOGI("CLIENT call doThatAndReturnSomething.");
     int32_t result = foo->doThatAndReturnSomething(2.0f);