Modified AIDL to support authentication

We need to pass an RpcContext with information
such as the caller's certificate. I also modified
the compiler so it does not use Container anymore
and uses Context

Change-Id: Ie1d247e8cac21f7f207a87b2eb77f3d1dd7215d4
diff --git a/tools/aidl/Type.h b/tools/aidl/Type.h
index c7b2e5d..536dc17 100755
--- a/tools/aidl/Type.h
+++ b/tools/aidl/Type.h
@@ -537,6 +537,7 @@
 
 extern Type* RPC_DATA_TYPE;
 extern Type* RPC_ERROR_TYPE;
+extern Type* RPC_CONTEXT_TYPE;
 extern Type* EVENT_FAKE_TYPE;
 
 extern Expression* NULL_VALUE;
diff --git a/tools/aidl/generate_java_rpc.cpp b/tools/aidl/generate_java_rpc.cpp
index bcd4b76..8353c45 100644
--- a/tools/aidl/generate_java_rpc.cpp
+++ b/tools/aidl/generate_java_rpc.cpp
@@ -5,8 +5,8 @@
 #include <stdlib.h>
 #include <string.h>
 
-Type* SERVICE_CONTAINER_TYPE = new Type("com.android.athome.service",
-        "AndroidAtHomeServiceContainer", Type::BUILT_IN, false, false, false);
+Type* SERVICE_CONTEXT_TYPE = new Type("android.content",
+        "Context", Type::BUILT_IN, false, false, false);
 Type* PRESENTER_BASE_TYPE = new Type("com.android.athome.service",
         "AndroidAtHomePresenter", Type::BUILT_IN, false, false, false);
 Type* PRESENTER_LISTENER_BASE_TYPE = new Type("com.android.athome.service",
@@ -21,6 +21,8 @@
         true, __FILE__, __LINE__);
 Type* RPC_ERROR_LISTENER_TYPE = new Type("com.android.athome.rpc", "RpcErrorHandler",
         Type::BUILT_IN, false, false, false);
+Type* RPC_CONTEXT_TYPE = new ParcelableType("com.android.athome.rpc", "RpcContext", true,
+        __FILE__, __LINE__);
 
 static void generate_create_from_data(Type* t, StatementBlock* addTo, const string& key,
         Variable* v, Variable* data, Variable** cl);
@@ -87,6 +89,7 @@
     Method* processMethod;
     Variable* actionParam;
     Variable* requestParam;
+    Variable* rpcContextParam;
     Variable* errorParam;
     Variable* requestData;
     Variable* resultData;
@@ -112,7 +115,7 @@
 void
 DispatcherClass::generate_process()
 {
-    // byte[] process(String action, byte[] params, RpcError status)
+    // byte[] process(String action, byte[] params, RpcContext context, RpcError status)
     this->processMethod = new Method;
         this->processMethod->modifiers = PUBLIC;
         this->processMethod->returnType = BYTE_TYPE;
@@ -126,6 +129,9 @@
     this->requestParam = new Variable(BYTE_TYPE, "requestParam", 1);
     this->processMethod->parameters.push_back(this->requestParam);
 
+    this->rpcContextParam = new Variable(RPC_CONTEXT_TYPE, "context", 0);
+    this->processMethod->parameters.push_back(this->rpcContextParam);    
+
     this->errorParam = new Variable(RPC_ERROR_TYPE, "errorParam", 0);
     this->processMethod->parameters.push_back(this->errorParam);
 
@@ -192,6 +198,9 @@
         arg = arg->next;
     }
 
+    // Add a final parameter: RpcContext. Contains data about
+    // incoming request (e.g., certificate)
+    realCall->arguments.push_back(new Variable(RPC_CONTEXT_TYPE, "context", 0));
 
     Type* returnType = NAMES.Search(method->type.type.data);
     if (returnType == EVENT_FAKE_TYPE) {
@@ -254,8 +263,10 @@
     IfStatement* fallthrough = new IfStatement();
         fallthrough->statements = new StatementBlock;
         fallthrough->statements->Add(new ReturnStatement(
-                    new MethodCall(SUPER_VALUE, "process", 3, this->actionParam, this->requestParam,
-                        this->errorParam)));
+                    new MethodCall(SUPER_VALUE, "process", 4, 
+                    this->actionParam, this->requestParam, 
+                    this->rpcContextParam,
+                    this->errorParam)));
     this->dispatchIfStatement->elseif = fallthrough;
     IfStatement* s = new IfStatement;
         s->statements = new StatementBlock;
@@ -446,7 +457,7 @@
 void
 ServiceBaseClass::generate_ctor()
 {
-    Variable* container = new Variable(SERVICE_CONTAINER_TYPE, "container");
+    Variable* context = new Variable(SERVICE_CONTEXT_TYPE, "context");
     Variable* name = new Variable(STRING_TYPE, "name");
     Variable* type = new Variable(STRING_TYPE, "type");
     Variable* version = new Variable(INT_TYPE, "version");
@@ -454,13 +465,13 @@
         ctor->modifiers = PUBLIC;
         ctor->name = class_name_leaf(this->type->Name());
         ctor->statements = new StatementBlock;
-        ctor->parameters.push_back(container);
+        ctor->parameters.push_back(context);
         ctor->parameters.push_back(name);
         ctor->parameters.push_back(type);
         ctor->parameters.push_back(version);
     this->elements.push_back(ctor);
 
-    ctor->statements->Add(new MethodCall("super", 4, container, name, type, version));
+    ctor->statements->Add(new MethodCall("super", 4, context, name, type, version));
 }
 
 // =================================================
@@ -794,6 +805,10 @@
                             arg->type.dimension));
         arg = arg->next;
     }
+
+    // Add the default RpcContext param to all methods
+    decl->parameters.push_back(new Variable(RPC_CONTEXT_TYPE, "context", 0));
+	
     serviceBaseClass->elements.push_back(decl);
     
 
@@ -858,6 +873,10 @@
                             arg->type.dimension));
         arg = arg->next;
     }
+
+    // Add a final parameter: RpcContext. Contains data about
+    // incoming request (e.g., certificate)
+    event->parameters.push_back(new Variable(RPC_CONTEXT_TYPE, "context", 0));
 }
 
 static void