Commit 4502ddc7 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Remove accounts and sign-in information from Omaha requests

This CL removes the code that used to add _numaccounts,
_numgoogleaccountsondevice and _numsignedin attributes to Omaha
requests.

Bug: 926273
Change-Id: I36edef48dc4d51cbed70ad1a7e14284cfa1c772f
Reviewed-on: https://chromium-review.googlesource.com/c/1451925Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Commit-Queue: Jochen Eisinger <jochen@chromium.org>
Auto-Submit: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629111}
parent 64f52d0f
...@@ -13,14 +13,9 @@ import android.util.Xml; ...@@ -13,14 +13,9 @@ import android.util.Xml;
import org.xmlpull.v1.XmlSerializer; import org.xmlpull.v1.XmlSerializer;
import org.chromium.base.BuildInfo; import org.chromium.base.BuildInfo;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.identity.SettingsSecureBasedIdentificationGenerator; import org.chromium.chrome.browser.identity.SettingsSecureBasedIdentificationGenerator;
import org.chromium.chrome.browser.identity.UniqueIdentificationGeneratorFactory; import org.chromium.chrome.browser.identity.UniqueIdentificationGeneratorFactory;
import org.chromium.chrome.browser.init.ProcessInitializationHandler;
import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.ui.base.DeviceFormFactor; import org.chromium.ui.base.DeviceFormFactor;
import java.io.IOException; import java.io.IOException;
...@@ -103,12 +98,6 @@ public abstract class RequestGenerator { ...@@ -103,12 +98,6 @@ public abstract class RequestGenerator {
serializer.attribute(null, "lang", getLanguage()); serializer.attribute(null, "lang", getLanguage());
serializer.attribute(null, "installage", String.valueOf(installAge)); serializer.attribute(null, "installage", String.valueOf(installAge));
serializer.attribute(null, "ap", getAdditionalParameters()); serializer.attribute(null, "ap", getAdditionalParameters());
// <code>_numaccounts</code> is actually number of profiles, which is always one for
// Chrome Android.
serializer.attribute(null, "_numaccounts", "1");
serializer.attribute(null, "_numgoogleaccountsondevice",
String.valueOf(getNumGoogleAccountsOnDevice()));
serializer.attribute(null, "_numsignedin", String.valueOf(getNumSignedIn()));
serializer.attribute( serializer.attribute(
null, "_dl_mgr_disabled", String.valueOf(getDownloadManagerState())); null, "_dl_mgr_disabled", String.valueOf(getDownloadManagerState()));
...@@ -187,43 +176,6 @@ public abstract class RequestGenerator { ...@@ -187,43 +176,6 @@ public abstract class RequestGenerator {
return applicationLabel + ";" + brand + ";" + model; return applicationLabel + ";" + brand + ";" + model;
} }
/**
* Returns the number of accounts on the device, bucketed into:
* 0 accounts, 1 account, or 2+ accounts.
*
* @return Number of accounts on the device, bucketed as above.
*/
@VisibleForTesting
public int getNumGoogleAccountsOnDevice() {
// RequestGenerator may be invoked from JobService or AlarmManager (through OmahaService),
// so have to make sure AccountManagerFacade instance is initialized.
ThreadUtils.runOnUiThreadBlocking(
() -> ProcessInitializationHandler.getInstance().initializePreNative());
int numAccounts = 0;
try {
numAccounts = AccountManagerFacade.get().getGoogleAccounts().size();
} catch (Exception e) {
Log.e(TAG, "Can't get number of accounts.", e);
}
switch (numAccounts) {
case 0:
return 0;
case 1:
return 1;
default:
return 2;
}
}
/**
* Determine number of accounts signed in.
*/
@VisibleForTesting
public int getNumSignedIn() {
// We only have a single account.
return ChromeSigninController.get().isSignedIn() ? 1 : 0;
}
/** /**
* Returns DownloadManager system service enabled state as * Returns DownloadManager system service enabled state as
* -1 - manager state unknown * -1 - manager state unknown
......
...@@ -22,7 +22,6 @@ import org.chromium.base.test.util.Feature; ...@@ -22,7 +22,6 @@ import org.chromium.base.test.util.Feature;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.omaha.MockRequestGenerator; import org.chromium.chrome.test.omaha.MockRequestGenerator;
import org.chromium.chrome.test.omaha.MockRequestGenerator.DeviceType; import org.chromium.chrome.test.omaha.MockRequestGenerator.DeviceType;
import org.chromium.chrome.test.omaha.MockRequestGenerator.SignedInStatus;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
...@@ -88,8 +87,8 @@ public class OmahaBaseTest { ...@@ -88,8 +87,8 @@ public class OmahaBaseTest {
@Override @Override
protected RequestGenerator createRequestGenerator(Context context) { protected RequestGenerator createRequestGenerator(Context context) {
mMockGenerator = new MockRequestGenerator(context, mMockGenerator = new MockRequestGenerator(
mIsOnTablet ? DeviceType.TABLET : DeviceType.HANDSET, SignedInStatus.FALSE); context, mIsOnTablet ? DeviceType.TABLET : DeviceType.HANDSET);
return mMockGenerator; return mMockGenerator;
} }
......
...@@ -22,7 +22,6 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner; ...@@ -22,7 +22,6 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.omaha.AttributeFinder; import org.chromium.chrome.test.omaha.AttributeFinder;
import org.chromium.chrome.test.omaha.MockRequestGenerator; import org.chromium.chrome.test.omaha.MockRequestGenerator;
import org.chromium.chrome.test.omaha.MockRequestGenerator.DeviceType; import org.chromium.chrome.test.omaha.MockRequestGenerator.DeviceType;
import org.chromium.chrome.test.omaha.MockRequestGenerator.SignedInStatus;
import org.chromium.components.signin.AccountManagerFacade; import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.test.util.AccountHolder; import org.chromium.components.signin.test.util.AccountHolder;
import org.chromium.components.signin.test.util.FakeAccountManagerDelegate; import org.chromium.components.signin.test.util.FakeAccountManagerDelegate;
...@@ -77,7 +76,7 @@ public class RequestGeneratorTest { ...@@ -77,7 +76,7 @@ public class RequestGeneratorTest {
UniqueIdentificationGeneratorFactory.clearGeneratorMapForTest(); UniqueIdentificationGeneratorFactory.clearGeneratorMapForTest();
// Creating a RequestGenerator should register the identification generator. // Creating a RequestGenerator should register the identification generator.
new MockRequestGenerator(context, DeviceType.HANDSET, SignedInStatus.FALSE); new MockRequestGenerator(context, DeviceType.HANDSET);
// Verify the identification generator exists and is of the correct type. // Verify the identification generator exists and is of the correct type.
UniqueIdentificationGenerator instance = UniqueIdentificationGeneratorFactory.getInstance( UniqueIdentificationGenerator instance = UniqueIdentificationGeneratorFactory.getInstance(
...@@ -89,88 +88,49 @@ public class RequestGeneratorTest { ...@@ -89,88 +88,49 @@ public class RequestGeneratorTest {
@SmallTest @SmallTest
@Feature({"Omaha"}) @Feature({"Omaha"})
public void testHandsetXMLCreationWithInstall() { public void testHandsetXMLCreationWithInstall() {
createAndCheckXML(DeviceType.HANDSET, SignedInStatus.FALSE, true); createAndCheckXML(DeviceType.HANDSET, true);
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"Omaha"}) @Feature({"Omaha"})
public void testHandsetXMLCreationWithoutInstall() { public void testHandsetXMLCreationWithoutInstall() {
createAndCheckXML(DeviceType.HANDSET, SignedInStatus.FALSE, false); createAndCheckXML(DeviceType.HANDSET, false);
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"Omaha"}) @Feature({"Omaha"})
public void testTabletXMLCreationWithInstall() { public void testTabletXMLCreationWithInstall() {
createAndCheckXML(DeviceType.TABLET, SignedInStatus.FALSE, true); createAndCheckXML(DeviceType.TABLET, true);
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"Omaha"}) @Feature({"Omaha"})
public void testTabletXMLCreationWithoutInstall() { public void testTabletXMLCreationWithoutInstall() {
createAndCheckXML(DeviceType.TABLET, SignedInStatus.FALSE, false); createAndCheckXML(DeviceType.TABLET, false);
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"Omaha"}) @Feature({"Omaha"})
public void testIsSignedIn() { public void testIsSignedIn() {
createAndCheckXML(DeviceType.HANDSET, SignedInStatus.TRUE, false); createAndCheckXML(DeviceType.HANDSET, false);
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"Omaha"}) @Feature({"Omaha"})
public void testIsNotSignedIn() { public void testIsNotSignedIn() {
createAndCheckXML(DeviceType.HANDSET, SignedInStatus.FALSE, false); createAndCheckXML(DeviceType.HANDSET, false);
}
@Test
@SmallTest
@Feature({"Omaha"})
public void testNoGoogleAccountsRetrieved() {
RequestGenerator generator =
createAndCheckXML(DeviceType.HANDSET, SignedInStatus.TRUE, false);
Assert.assertEquals(0, generator.getNumGoogleAccountsOnDevice());
}
@Test
@SmallTest
@Feature({"Omaha"})
public void testOneGoogleAccountRetrieved() {
RequestGenerator generator = createAndCheckXML(DeviceType.HANDSET, SignedInStatus.TRUE,
false, new Account("clanktester@this.com", "com.google"));
Assert.assertEquals(1, generator.getNumGoogleAccountsOnDevice());
}
@Test
@SmallTest
@Feature({"Omaha"})
public void testTwoGoogleAccountsRetrieved() {
RequestGenerator generator = createAndCheckXML(DeviceType.HANDSET, SignedInStatus.TRUE,
false, new Account("clanktester@gmail.com", "com.google"),
new Account("googleguy@elsewhere.com", "com.google"));
Assert.assertEquals(2, generator.getNumGoogleAccountsOnDevice());
}
@Test
@SmallTest
@Feature({"Omaha"})
public void testThreeGoogleAccountsExist() {
RequestGenerator generator = createAndCheckXML(DeviceType.HANDSET, SignedInStatus.TRUE,
false, new Account("clanktester@gmail.com", "com.google"),
new Account("googleguy@elsewhere.com", "com.google"),
new Account("ImInATest@gmail.com", "com.google"));
Assert.assertEquals(2, generator.getNumGoogleAccountsOnDevice());
} }
/** /**
* Checks that the XML is being created properly. * Checks that the XML is being created properly.
*/ */
private RequestGenerator createAndCheckXML(DeviceType deviceType, SignedInStatus signInStatus, private RequestGenerator createAndCheckXML(
boolean sendInstallEvent, Account... accounts) { DeviceType deviceType, boolean sendInstallEvent, Account... accounts) {
Context targetContext = InstrumentationRegistry.getTargetContext(); Context targetContext = InstrumentationRegistry.getTargetContext();
AdvancedMockContext context = new AdvancedMockContext(targetContext); AdvancedMockContext context = new AdvancedMockContext(targetContext);
...@@ -186,9 +146,7 @@ public class RequestGeneratorTest { ...@@ -186,9 +146,7 @@ public class RequestGeneratorTest {
String version = "1.2.3.4"; String version = "1.2.3.4";
long installAge = 42; long installAge = 42;
MockRequestGenerator generator = MockRequestGenerator generator = new MockRequestGenerator(context, deviceType);
new MockRequestGenerator(context, deviceType, signInStatus);
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);
...@@ -226,12 +184,6 @@ public class RequestGeneratorTest { ...@@ -226,12 +184,6 @@ public class RequestGeneratorTest {
checkForAttributeAndValue(xml, "request", "userid", "{" + generator.getDeviceID() + "}"); checkForAttributeAndValue(xml, "request", "userid", "{" + generator.getDeviceID() + "}");
checkForAttributeAndValue(xml, "app", "_numaccounts", "1");
checkForAttributeAndValue(xml, "app", "_numgoogleaccountsondevice",
String.valueOf(generator.getNumGoogleAccountsOnDevice()));
checkForAttributeAndValue(
xml, "app", "_numsignedin", String.valueOf(generator.getNumSignedIn()));
return generator; return generator;
} }
......
...@@ -14,8 +14,6 @@ public class MockRequestGenerator extends RequestGenerator { ...@@ -14,8 +14,6 @@ public class MockRequestGenerator extends RequestGenerator {
HANDSET, TABLET HANDSET, TABLET
} }
public enum SignedInStatus { TRUE, FALSE }
public static final String UUID_PHONE = "uuid_phone"; public static final String UUID_PHONE = "uuid_phone";
public static final String UUID_TABLET = "uuid_tablet"; public static final String UUID_TABLET = "uuid_tablet";
public static final String SERVER_URL = "http://totallylegitserver.com"; public static final String SERVER_URL = "http://totallylegitserver.com";
...@@ -29,13 +27,9 @@ public class MockRequestGenerator extends RequestGenerator { ...@@ -29,13 +27,9 @@ public class MockRequestGenerator extends RequestGenerator {
private final boolean mIsOnTablet; private final boolean mIsOnTablet;
private final boolean mIsSignedIn; public MockRequestGenerator(Context context, DeviceType deviceType) {
public MockRequestGenerator(
Context context, DeviceType deviceType, SignedInStatus signInStatus) {
super(context); super(context);
mIsOnTablet = deviceType == DeviceType.TABLET; mIsOnTablet = deviceType == DeviceType.TABLET;
mIsSignedIn = signInStatus == SignedInStatus.TRUE;
} }
@Override @Override
...@@ -78,11 +72,6 @@ public class MockRequestGenerator extends RequestGenerator { ...@@ -78,11 +72,6 @@ public class MockRequestGenerator extends RequestGenerator {
return LANGUAGE; return LANGUAGE;
} }
@Override
public int getNumSignedIn() {
return mIsSignedIn ? 1 : 0;
}
@Override @Override
public String getAdditionalParameters() { public String getAdditionalParameters() {
return ADDITIONAL_PARAMETERS; return ADDITIONAL_PARAMETERS;
......
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