Commit 51f261c5 authored by Joshua Pawlicki's avatar Joshua Pawlicki Committed by Commit Bot

dlrc/dla for android Omaha client

Bug: 1056621
Change-Id: I5bf7da8366018d9cff7c581d78ac1e2c8f8e962b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2078411Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Commit-Queue: Joshua Pawlicki <waffles@chromium.org>
Auto-Submit: Joshua Pawlicki <waffles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748714}
parent fc4869db
......@@ -63,10 +63,12 @@ public class OmahaBase {
public static class VersionConfig {
public final String latestVersion;
public final String downloadUrl;
public final int serverDate;
protected VersionConfig(String latestVersion, String downloadUrl) {
protected VersionConfig(String latestVersion, String downloadUrl, int serverDate) {
this.latestVersion = latestVersion;
this.downloadUrl = downloadUrl;
this.serverDate = serverDate;
}
}
......@@ -76,6 +78,7 @@ public class OmahaBase {
static final String PREF_INSTALL_SOURCE = "installSource";
static final String PREF_LATEST_VERSION = "latestVersion";
static final String PREF_MARKET_URL = "marketURL";
static final String PREF_SERVER_DATE = "serverDate";
static final String PREF_PERSISTED_REQUEST_ID = "persistedRequestID";
static final String PREF_SEND_INSTALL_EVENT = "sendInstallEvent";
static final String PREF_TIMESTAMP_FOR_NEW_REQUEST = "timestampForNewRequest";
......@@ -85,6 +88,8 @@ public class OmahaBase {
static final int MIN_API_JOB_SCHEDULER = Build.VERSION_CODES.M;
private static final int UNKNOWN_DATE = -2;
/** Whether or not the Omaha server should really be contacted. */
private static boolean sIsDisabled;
......@@ -125,6 +130,7 @@ public class OmahaBase {
private long mTimestampOfInstall;
private long mTimestampForNextPostAttempt;
private long mTimestampForNewRequest;
private int mServerDate;
private String mInstallSource;
protected VersionConfig mVersionConfig;
protected boolean mSendInstallEvent;
......@@ -242,8 +248,9 @@ public class OmahaBase {
currentTimestamp, mTimestampOfInstall, mCurrentRequest.isSendInstallEvent());
String version =
VersionNumberGetter.getInstance().getCurrentlyUsedVersion(getContext());
String xml = getRequestGenerator().generateXML(
sessionID, version, installAgeInDays, mCurrentRequest);
String xml = getRequestGenerator().generateXML(sessionID, version, installAgeInDays,
mVersionConfig == null ? UNKNOWN_DATE : mVersionConfig.serverDate,
mCurrentRequest);
// Send the request to the server & wait for a response.
String response = postRequest(currentTimestamp, xml);
......@@ -538,10 +545,14 @@ public class OmahaBase {
versionConfig == null ? "" : versionConfig.latestVersion);
editor.putString(
OmahaBase.PREF_MARKET_URL, versionConfig == null ? "" : versionConfig.downloadUrl);
if (versionConfig != null) {
editor.putInt(OmahaBase.PREF_SERVER_DATE, versionConfig.serverDate);
}
}
static VersionConfig getVersionConfig(SharedPreferences sharedPref) {
return new VersionConfig(sharedPref.getString(OmahaBase.PREF_LATEST_VERSION, ""),
sharedPref.getString(OmahaBase.PREF_MARKET_URL, ""));
sharedPref.getString(OmahaBase.PREF_MARKET_URL, ""),
sharedPref.getInt(OmahaBase.PREF_SERVER_DATE, -2));
}
}
......@@ -70,7 +70,7 @@ public abstract class RequestGenerator {
* with some additional dummy values supplied.
*/
public String generateXML(String sessionID, String versionName, long installAge,
RequestData data) throws RequestFailureException {
int lastCheckDate, RequestData data) throws RequestFailureException {
XmlSerializer serializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
try {
......@@ -86,6 +86,7 @@ public abstract class RequestGenerator {
serializer.attribute(null, "sessionid", "{" + sessionID + "}");
serializer.attribute(null, "installsource", data.getInstallSource());
serializer.attribute(null, "userid", "{" + getDeviceID() + "}");
serializer.attribute(null, "dedup", "uid");
// Set up <os platform="android"... />
serializer.startTag(null, "os");
......@@ -124,9 +125,11 @@ public abstract class RequestGenerator {
serializer.startTag(null, "updatecheck");
serializer.endTag(null, "updatecheck");
// Set up <ping active="1" />
// Set up <ping active="1" rd="..." ad="..." />
serializer.startTag(null, "ping");
serializer.attribute(null, "active", "1");
serializer.attribute(null, "ad", String.valueOf(lastCheckDate));
serializer.attribute(null, "rd", String.valueOf(lastCheckDate));
serializer.endTag(null, "ping");
}
......
......@@ -15,7 +15,7 @@ import org.chromium.chrome.browser.omaha.XMLParser.Node;
*
* Expects XML formatted like:
* <?xml version="1.0" encoding="UTF-8"?>
* <daystart elapsed_seconds="65524"/>
* <daystart elapsed_days="4804" elapsed_seconds="65524"/>
* <app appid="{appid}" status="ok">
* <updatecheck status="ok">
* <urls>
......@@ -58,6 +58,7 @@ public class ResponseParser {
private final boolean mStrictParsingMode;
private Integer mDaystartSeconds;
private Integer mDaystartDays;
private String mAppStatus;
private String mUpdateStatus;
......@@ -86,7 +87,7 @@ public class ResponseParser {
XMLParser parser = new XMLParser(xml);
Node rootNode = parser.getRootNode();
parseRootNode(rootNode);
return new VersionConfig(getNewVersion(), getURL());
return new VersionConfig(getNewVersion(), getURL(), getDaystartDays());
}
public int getDaystartSeconds() {
......@@ -94,6 +95,11 @@ public class ResponseParser {
return mDaystartSeconds;
}
public int getDaystartDays() {
if (mDaystartDays == null) return 0;
return mDaystartDays;
}
public String getNewVersion() {
return mNewVersion;
}
......@@ -181,6 +187,7 @@ public class ResponseParser {
private boolean parseDaystartNode(Node node) throws RequestFailureException {
try {
mDaystartSeconds = Integer.parseInt(node.attributes.get("elapsed_seconds"));
mDaystartDays = Integer.parseInt(node.attributes.get("elapsed_days"));
} catch (NumberFormatException e) {
return logError(node, RequestFailureException.ERROR_PARSE_DAYSTART);
}
......
......@@ -622,7 +622,7 @@ public class OmahaBaseTest {
String response = "";
response += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
response += "<response protocol=\"3.0\" server=\"prod\">";
response += "<daystart elapsed_seconds=\"12345\"/>";
response += "<daystart elapsed_days=\"4088\" elapsed_seconds=\"12345\"/>";
response += "<app appid=\"";
response += (isOnTablet ? MockRequestGenerator.UUID_TABLET
: MockRequestGenerator.UUID_PHONE);
......
......@@ -185,6 +185,7 @@ public class RequestGeneratorTest {
String requestId = "random_request_id";
String version = "1.2.3.4";
long installAge = 42;
int dateLastActive = 4088;
MockRequestGenerator generator =
new MockRequestGenerator(context, deviceType, signInStatus);
......@@ -192,7 +193,7 @@ public class RequestGeneratorTest {
String xml = null;
try {
RequestData data = new RequestData(sendInstallEvent, 0, requestId, INSTALL_SOURCE);
xml = generator.generateXML(sessionId, version, installAge, data);
xml = generator.generateXML(sessionId, version, installAge, dateLastActive, data);
} catch (RequestFailureException e) {
Assert.fail("XML generation failed.");
}
......@@ -220,6 +221,8 @@ public class RequestGeneratorTest {
Assert.assertFalse("Update check and install event are mutually exclusive",
checkForTag(xml, "event"));
checkForAttributeAndValue(xml, "ping", "active", "1");
checkForAttributeAndValue(xml, "ping", "rd", String.valueOf(dateLastActive));
checkForAttributeAndValue(xml, "ping", "ad", String.valueOf(dateLastActive));
Assert.assertTrue("Update check and install event are mutually exclusive",
checkForTag(xml, "updatecheck"));
}
......
......@@ -49,9 +49,9 @@ public class ResponseParserTest {
* @param updateStatus Status to use for the <updatecheck> element.
* @return The completed XML.
*/
private static String createTestXML(String xmlProtocol, String elapsedSeconds,
String appStatus, boolean addInstall, boolean addPing, String updateStatus,
String updateUrl) {
private static String createTestXML(String xmlProtocol, String elapsedDays,
String elapsedSeconds, String appStatus, boolean addInstall, boolean addPing,
String updateStatus, String updateUrl) {
StringWriter writer = new StringWriter();
try {
XmlSerializer serializer = Xml.newSerializer();
......@@ -66,9 +66,14 @@ public class ResponseParserTest {
}
// Create <daystart> element.
if (elapsedSeconds != null) {
if (elapsedSeconds != null || elapsedDays != null) {
serializer.startTag(null, "daystart");
if (elapsedDays != null) {
serializer.attribute(null, "elapsed_days", elapsedDays);
}
if (elapsedSeconds != null) {
serializer.attribute(null, "elapsed_seconds", elapsedSeconds);
}
serializer.endTag(null, "daystart");
}
......@@ -190,13 +195,14 @@ public class ResponseParserTest {
*/
private static void runSuccessTest(String appStatus, boolean addInstall, boolean addPing,
String updateStatus) throws RequestFailureException {
String xml =
createTestXML("3.0", "12345", appStatus, addInstall, addPing, updateStatus, URL);
String xml = createTestXML(
"3.0", "4088", "12345", appStatus, addInstall, addPing, updateStatus, URL);
ResponseParser parser =
new ResponseParser(true, "{APP_ID}", addInstall, addPing, updateStatus != null);
OmahaBase.VersionConfig versionConfig = parser.parseResponse(xml);
Assert.assertEquals("elapsed_seconds doesn't match.", 12345, parser.getDaystartSeconds());
Assert.assertEquals("elapsed_days doesn't match.", 4088, parser.getDaystartDays());
Assert.assertEquals("<app> status doesn't match.", appStatus, parser.getAppStatus());
Assert.assertEquals(
"<updatecheck> status doesn't match.", updateStatus, parser.getUpdateStatus());
......@@ -297,64 +303,79 @@ public class ResponseParserTest {
@Test
@Feature({"Omaha"})
public void testBadResponseProtocol() {
String xml =
createTestXML("2.0", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
String xml = createTestXML(
"2.0", "4088", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_RESPONSE, false, false, false);
}
@Test
@Feature({"Omaha"})
public void testFailMissingDaystart() {
String xml =
createTestXML("3.0", null, APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
String xml = createTestXML(
"3.0", null, null, APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_DAYSTART, false, false, true);
}
@Test
@Feature({"Omaha"})
public void testFailMissingDaystartSeconds() {
String xml = createTestXML(
"3.0", "4088", null, APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_DAYSTART, false, false, true);
}
@Test
@Feature({"Omaha"})
public void testFailMissingDaystartDays() {
String xml = createTestXML(
"3.0", null, "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_DAYSTART, false, false, true);
}
@Test
@Feature({"Omaha"})
public void testAppTagMissingUpdatecheck() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_OK, true, false, null, URL);
String xml = createTestXML("3.0", "4088", "12345", APP_STATUS_OK, true, false, null, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_UPDATECHECK, true, false, true);
}
@Test
@Feature({"Omaha"})
public void testAppTagUnexpectedUpdatecheck() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_OK, true, false, UPDATE_STATUS_OK, URL);
String xml = createTestXML(
"3.0", "4088", "12345", APP_STATUS_OK, true, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_UPDATECHECK, true, false, false);
}
@Test
@Feature({"Omaha"})
public void testAppTagMissingPing() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
String xml = createTestXML(
"3.0", "4088", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_PING, false, true, true);
}
@Test
@Feature({"Omaha"})
public void testAppTagUnexpectedPing() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_OK, false, true, UPDATE_STATUS_OK, URL);
String xml = createTestXML(
"3.0", "4088", "12345", APP_STATUS_OK, false, true, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_PING, false, false, true);
}
@Test
@Feature({"Omaha"})
public void testAppTagMissingInstall() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
String xml = createTestXML(
"3.0", "4088", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_EVENT, true, false, true);
}
@Test
@Feature({"Omaha"})
public void testAppTagUnexpectedInstall() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_OK, true, false, UPDATE_STATUS_OK, URL);
String xml = createTestXML(
"3.0", "4088", "12345", APP_STATUS_OK, true, false, UPDATE_STATUS_OK, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_EVENT, false, false, true);
}
......@@ -362,7 +383,7 @@ public class ResponseParserTest {
@Feature({"Omaha"})
public void testAppTagStatusError() {
String xml =
createTestXML("3.0", "12345", APP_STATUS_ERROR, false, false, null, URL);
createTestXML("3.0", "4088", "12345", APP_STATUS_ERROR, false, false, null, URL);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_APP, false, false, false);
}
......@@ -370,7 +391,7 @@ public class ResponseParserTest {
@Feature({"Omaha"})
public void testUpdatecheckMissingUrl() {
String xml = createTestXML(
"3.0", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, null);
"3.0", "4088", "12345", APP_STATUS_OK, false, false, UPDATE_STATUS_OK, null);
runFailureTest(xml, RequestFailureException.ERROR_PARSE_URLS, false, false, true);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment