@Override public void write(JSONStringer writer) throws JSONException { JSONUtils.write(writer, LOCAL_ID, getLocalId()); }
@Test public void collectDeviceId() { CommonSchemaLog log = new CommonSchemaEventLog(); log.setExt(new Extensions()); log.getExt().setDevice(new DeviceExtension()); /* Mock context. */ mockStatic(Secure.class); when(Secure.getString(any(ContentResolver.class), anyString())).thenReturn("mockDeviceId"); /* Get property configurator and collect device ID. */ PropertyConfigurator pc = Analytics.getTransmissionTarget("test").getPropertyConfigurator(); pc.collectDeviceId(); /* Simulate what the pipeline does to convert from App Center to Common Schema. */ log.addTransmissionTarget("test"); log.setTag(Analytics.getTransmissionTarget("test")); pc.onPreparingLog(log, "groupName"); /* Assert device ID is collected. */ assertEquals("a:mockDeviceId", log.getExt().getDevice().getLocalId()); }
@Test public void collectDeviceIdSavedWhenDisabled() { CommonSchemaLog log = new CommonSchemaEventLog(); log.setExt(new Extensions()); log.getExt().setDevice(new DeviceExtension()); /* Mock context. */ mockStatic(Secure.class); when(Secure.getString(any(ContentResolver.class), anyString())).thenReturn("mockDeviceId"); /* Disable Analytics. */ Analytics.setEnabled(false).get(); /* Get property configurator and collect device ID. */ PropertyConfigurator pc = Analytics.getTransmissionTarget("test").getPropertyConfigurator(); pc.collectDeviceId(); /* Simulate what the pipeline does to convert from App Center to Common Schema. */ log.addTransmissionTarget("test"); log.setTag(Analytics.getTransmissionTarget("test")); /* Enable and simulate log preparing. */ Analytics.setEnabled(true).get(); pc.onPreparingLog(log, "groupName"); /* Assert device ID is collected. */ assertEquals("a:mockDeviceId", log.getExt().getDevice().getLocalId()); }
assertNull(logBeforeSetProperty.getExt().getApp().getName()); assertNull(logBeforeSetProperty.getExt().getUser().getLocalId()); assertNull(logBeforeSetProperty.getExt().getDevice().getLocalId()); assertEquals("appName", logAfterSetProperty.getExt().getApp().getName()); assertEquals("c:alice", logAfterSetProperty.getExt().getUser().getLocalId()); assertEquals("a:mockDeviceId", logAfterSetProperty.getExt().getDevice().getLocalId());