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