autoupdate: Return response with client's app ID

Currently in autoupdate we sent a default hard coded app ID to the
client. However, this is not the bahvior of omaha, as omaha always, reply with
the same app ID requested by the user. This CL, modifes this bahavior in
autoupdate to return the app ID associated with the client's request.

BUG=chromium:821514
TEST=cros flash

Change-Id: I7cd36c8e7ed6e36bed257a5373e62483136b585e
Reviewed-on: https://chromium-review.googlesource.com/961585
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Xixuan Wu <xixuan@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
diff --git a/autoupdate_lib.py b/autoupdate_lib.py
index eb39412..95a5254 100644
--- a/autoupdate_lib.py
+++ b/autoupdate_lib.py
@@ -11,7 +11,6 @@
 import time
 from xml.dom import minidom
 
-
 # Update events and result codes.
 EVENT_TYPE_UNKNOWN = 0
 EVENT_TYPE_DOWNLOAD_COMPLETE = 1
@@ -26,10 +25,6 @@
 EVENT_RESULT_UPDATE_DEFERRED = 9
 
 
-# A default app_id value.
-_APP_ID = '87efface-864d-49a5-9bb3-4b050a7c227a'
-
-
 # Responses for the various Omaha protocols indexed by the protocol version.
 #
 # Update available responses:
@@ -37,7 +32,7 @@
 _UPDATE_RESPONSE['2.0'] = """<?xml version="1.0" encoding="UTF-8"?>
   <gupdate xmlns="http://www.google.com/update2/response" protocol="2.0">
     <daystart elapsed_seconds="%(time_elapsed)s"/>
-    <app appid="{%(appid)s}" status="ok">
+    <app appid="%(appid)s" status="ok">
       <ping status="ok"/>
       <updatecheck
         ChromeOSVersion="999999.0.0"
@@ -54,7 +49,7 @@
 _UPDATE_RESPONSE['3.0'] = """<?xml version="1.0" encoding="UTF-8"?>
   <response protocol="3.0">
     <daystart elapsed_seconds="%(time_elapsed)s"/>
-    <app appid="{%(appid)s}" status="ok">
+    <app appid="%(appid)s" status="ok">
       <ping status="ok"/>
       <updatecheck status="ok">
         <urls>
@@ -83,7 +78,7 @@
 _NO_UPDATE_RESPONSE['2.0'] = """<?xml version="1.0" encoding="UTF-8"?>
   <gupdate xmlns="http://www.google.com/update2/response" protocol="2.0">
     <daystart elapsed_seconds="%(time_elapsed)s"/>
-    <app appid="{%(appid)s}" status="ok">
+    <app appid="%(appid)s" status="ok">
       <ping status="ok"/>
       <updatecheck status="noupdate"/>
     </app>
@@ -91,7 +86,7 @@
 _NO_UPDATE_RESPONSE['3.0'] = """<?xml version="1.0" encoding="UTF-8"?>
   <response protocol="3.0">
     <daystart elapsed_seconds="%(time_elapsed)s"/>
-    <app appid="{%(appid)s}" status="ok">
+    <app appid="%(appid)s" status="ok">
       <ping status="ok"/>
       <updatecheck status="noupdate"/>
     </app>
@@ -103,7 +98,7 @@
 _EVENT_RESPONSE['2.0'] = """<?xml version="1.0" encoding="UTF-8"?>
   <gupdate xmlns="http://www.google.com/update2/response" protocol="2.0">
     <daystart elapsed_seconds="%(time_elapsed)s"/>
-    <app appid="{%(appid)s}" status="ok">
+    <app appid="%(appid)s" status="ok">
       <ping status="ok"/>
       <event status="ok"/>
     </app>
@@ -111,7 +106,7 @@
 _EVENT_RESPONSE['3.0'] = """<?xml version="1.0" encoding="UTF-8"?>
   <response protocol="3.0">
     <daystart elapsed_seconds="%(time_elapsed)s"/>
-    <app appid="{%(appid)s}" status="ok">
+    <app appid="%(appid)s" status="ok">
       <ping status="ok"/>
       <event status="ok"/>
     </app>
@@ -128,10 +123,10 @@
   return now[3] * 3600 + now[4] * 60 + now[5]
 
 
-def GetCommonResponseValues():
+def GetCommonResponseValues(appid):
   """Returns a dictionary of default values for the response."""
   response_values = {}
-  response_values['appid'] = _APP_ID
+  response_values['appid'] = appid
   response_values['time_elapsed'] = GetSecondsSinceMidnight()
   return response_values
 
@@ -152,7 +147,7 @@
 
 
 def GetUpdateResponse(sha1, sha256, size, url, is_delta_format, metadata_size,
-                      signed_metadata_hash, public_key, protocol,
+                      signed_metadata_hash, public_key, protocol, appid,
                       critical_update=False):
   """Returns a protocol-specific response to the client for a new update.
 
@@ -166,12 +161,13 @@
     signed_metadata_hash: the signed metadata hash or None if not signed.
     public_key: the public key to transmit to the client or None if no key.
     protocol: client's protocol version from the request Xml.
+    appid: the appid associated with the response.
     critical_update: whether this is a critical update.
 
   Returns:
     Xml string to be passed back to client.
   """
-  response_values = GetCommonResponseValues()
+  response_values = GetCommonResponseValues(appid)
   response_values['sha1'] = sha1
   response_values['sha256'] = sha256
   response_values['size'] = size
@@ -199,29 +195,31 @@
   return GetSubstitutedResponse(_UPDATE_RESPONSE, protocol, response_values)
 
 
-def GetNoUpdateResponse(protocol):
+def GetNoUpdateResponse(protocol, appid):
   """Returns a protocol-specific response to the client for no update.
 
   Args:
     protocol: client's protocol version from the request Xml.
+    appid: the appid associated with the response.
 
   Returns:
     Xml string to be passed back to client.
   """
-  response_values = GetCommonResponseValues()
+  response_values = GetCommonResponseValues(appid)
   return GetSubstitutedResponse(_NO_UPDATE_RESPONSE, protocol, response_values)
 
 
-def GetEventResponse(protocol):
+def GetEventResponse(protocol, appid):
   """Returns a protocol-specific response to a client event notification.
 
   Args:
     protocol: client's protocol version from the request Xml.
+    appid: the appid associated with the response.
 
   Returns:
     Xml string to be passed back to client.
   """
-  response_values = GetCommonResponseValues()
+  response_values = GetCommonResponseValues(appid)
   return GetSubstitutedResponse(_EVENT_RESPONSE, protocol, response_values)