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;
import org.xmlpull.v1.XmlSerializer;
import org.chromium.base.BuildInfo;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.identity.SettingsSecureBasedIdentificationGenerator;
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 java.io.IOException;
......@@ -103,12 +98,6 @@ public abstract class RequestGenerator {
serializer.attribute(null, "lang", getLanguage());
serializer.attribute(null, "installage", String.valueOf(installAge));
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(
null, "_dl_mgr_disabled", String.valueOf(getDownloadManagerState()));
......@@ -187,43 +176,6 @@ public abstract class RequestGenerator {
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
* -1 - manager state unknown
......
......@@ -22,7 +22,6 @@ import org.chromium.base.test.util.Feature;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.omaha.MockRequestGenerator;
import org.chromium.chrome.test.omaha.MockRequestGenerator.DeviceType;
import org.chromium.chrome.test.omaha.MockRequestGenerator.SignedInStatus;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
......@@ -88,8 +87,8 @@ public class OmahaBaseTest {
@Override
protected RequestGenerator createRequestGenerator(Context context) {
mMockGenerator = new MockRequestGenerator(context,
mIsOnTablet ? DeviceType.TABLET : DeviceType.HANDSET, SignedInStatus.FALSE);
mMockGenerator = new MockRequestGenerator(
context, mIsOnTablet ? DeviceType.TABLET : DeviceType.HANDSET);
return mMockGenerator;
}
......
......@@ -22,7 +22,6 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.omaha.AttributeFinder;
import org.chromium.chrome.test.omaha.MockRequestGenerator;
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.test.util.AccountHolder;
import org.chromium.components.signin.test.util.FakeAccountManagerDelegate;
......@@ -77,7 +76,7 @@ public class RequestGeneratorTest {
UniqueIdentificationGeneratorFactory.clearGeneratorMapForTest();
// 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.
UniqueIdentificationGenerator instance = UniqueIdentificationGeneratorFactory.getInstance(
......@@ -89,88 +88,49 @@ public class RequestGeneratorTest {
@SmallTest
@Feature({"Omaha"})
public void testHandsetXMLCreationWithInstall() {
createAndCheckXML(DeviceType.HANDSET, SignedInStatus.FALSE, true);
createAndCheckXML(DeviceType.HANDSET, true);
}
@Test
@SmallTest
@Feature({"Omaha"})
public void testHandsetXMLCreationWithoutInstall() {
createAndCheckXML(DeviceType.HANDSET, SignedInStatus.FALSE, false);
createAndCheckXML(DeviceType.HANDSET, false);
}
@Test
@SmallTest
@Feature({"Omaha"})
public void testTabletXMLCreationWithInstall() {
createAndCheckXML(DeviceType.TABLET, SignedInStatus.FALSE, true);
createAndCheckXML(DeviceType.TABLET, true);
}
@Test
@SmallTest
@Feature({"Omaha"})
public void testTabletXMLCreationWithoutInstall() {
createAndCheckXML(DeviceType.TABLET, SignedInStatus.FALSE, false);
createAndCheckXML(DeviceType.TABLET, false);
}
@Test
@SmallTest
@Feature({"Omaha"})
public void testIsSignedIn() {
createAndCheckXML(DeviceType.HANDSET, SignedInStatus.TRUE, false);
createAndCheckXML(DeviceType.HANDSET, false);
}
@Test
@SmallTest
@Feature({"Omaha"})
public void testIsNotSignedIn() {
createAndCheckXML(DeviceType.HANDSET, SignedInStatus.FALSE, 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());
createAndCheckXML(DeviceType.HANDSET, false);
}
/**
* Checks that the XML is being created properly.
*/
private RequestGenerator createAndCheckXML(DeviceType deviceType, SignedInStatus signInStatus,
boolean sendInstallEvent, Account... accounts) {
private RequestGenerator createAndCheckXML(
DeviceType deviceType, boolean sendInstallEvent, Account... accounts) {
Context targetContext = InstrumentationRegistry.getTargetContext();
AdvancedMockContext context = new AdvancedMockContext(targetContext);
......@@ -186,9 +146,7 @@ public class RequestGeneratorTest {
String version = "1.2.3.4";
long installAge = 42;
MockRequestGenerator generator =
new MockRequestGenerator(context, deviceType, signInStatus);
MockRequestGenerator generator = new MockRequestGenerator(context, deviceType);
String xml = null;
try {
RequestData data = new RequestData(sendInstallEvent, 0, requestId, INSTALL_SOURCE);
......@@ -226,12 +184,6 @@ public class RequestGeneratorTest {
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;
}
......
......@@ -14,8 +14,6 @@ public class MockRequestGenerator extends RequestGenerator {
HANDSET, TABLET
}
public enum SignedInStatus { TRUE, FALSE }
public static final String UUID_PHONE = "uuid_phone";
public static final String UUID_TABLET = "uuid_tablet";
public static final String SERVER_URL = "http://totallylegitserver.com";
......@@ -29,13 +27,9 @@ public class MockRequestGenerator extends RequestGenerator {
private final boolean mIsOnTablet;
private final boolean mIsSignedIn;
public MockRequestGenerator(
Context context, DeviceType deviceType, SignedInStatus signInStatus) {
public MockRequestGenerator(Context context, DeviceType deviceType) {
super(context);
mIsOnTablet = deviceType == DeviceType.TABLET;
mIsSignedIn = signInStatus == SignedInStatus.TRUE;
}
@Override
......@@ -78,11 +72,6 @@ public class MockRequestGenerator extends RequestGenerator {
return LANGUAGE;
}
@Override
public int getNumSignedIn() {
return mIsSignedIn ? 1 : 0;
}
@Override
public String getAdditionalParameters() {
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