libbinder: disallow upgrade of explicit version

If we have explicitly set a version, we want to test that that version
is actually being used, and we don't want the other side of the
connection to decide to artificially upgrade the version.

Bug: 182938972
Test: binderRpcTest (w/ Cls to simulate versions added)
Change-Id: Id784672100c0445d5ea77c4fc3b063daa5efa0b0
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp
index 90ce4d6..254b99c 100644
--- a/libs/binder/RpcSession.cpp
+++ b/libs/binder/RpcSession.cpp
@@ -87,6 +87,12 @@
     }
 
     std::lock_guard<std::mutex> _l(mMutex);
+    if (mProtocolVersion && version > *mProtocolVersion) {
+        ALOGE("Cannot upgrade explicitly capped protocol version %u to newer version %u",
+              *mProtocolVersion, version);
+        return false;
+    }
+
     mProtocolVersion = version;
     return true;
 }