public static Device generateNewDevice(Context context) { Device device = new Device(); device.setOsName("Android"); device.setOsVersion(Build.VERSION.RELEASE); device.setOsBuild(Build.VERSION.INCREMENTAL); device.setOsApiLevel(Build.VERSION.SDK_INT); device.setManufacturer(Build.MANUFACTURER); device.setModel(Build.MODEL); device.setBoard(Build.BOARD); device.setProduct(Build.PRODUCT); device.setBrand(Build.BRAND); device.setCpu(Build.CPU_ABI); device.setDevice(Build.DEVICE); device.setUuid(Util.getAndroidId(context)); device.setBuildType(Build.TYPE); device.setBuildId(Build.ID); AdvertiserManager.AdvertisingIdClientInfo info = AdvertiserManager.getAdvertisingIdClientInfo(); if (info != null && !info.isLimitAdTrackingEnabled()) { device.setAdvertiserId(info.getId()); } else { ApptentiveLog.w("Advertising ID tracking is not available or limited"); device.setCarrier(tm.getSimOperatorName()); device.setCurrentCarrier(tm.getNetworkOperatorName()); device.setNetworkType(Constants.networkTypeAsString(tm.getNetworkType())); device.setBootloaderVersion((String) Build.class.getField("BOOTLOADER").get(null)); } catch (Exception e) {
if (oldDevice == null || !equal(oldDevice.getUuid(), newDevice.getUuid())) { ret.setUuid(newDevice.getUuid()); changed = true; if (oldDevice == null || !equal(oldDevice.getOsName(), newDevice.getOsName())) { ret.setOsName(newDevice.getOsName()); changed = true; if (oldDevice == null || !equal(oldDevice.getOsVersion(), newDevice.getOsVersion())) { ret.setOsVersion(newDevice.getOsVersion()); changed = true; if (oldDevice == null || !equal(oldDevice.getOsBuild(), newDevice.getOsBuild())) { ret.setOsBuild(newDevice.getOsBuild()); changed = true; if (oldDevice == null || oldDevice.getOsApiLevel() != newDevice.getOsApiLevel()) { ret.setOsApiLevel(String.valueOf(newDevice.getOsApiLevel())); changed = true; if (oldDevice == null || !equal(oldDevice.getManufacturer(), newDevice.getManufacturer())) { ret.setManufacturer(newDevice.getManufacturer()); changed = true; if (oldDevice == null || !equal(oldDevice.getModel(), newDevice.getModel())) { ret.setModel(newDevice.getModel()); changed = true; if (oldDevice == null || !equal(oldDevice.getBoard(), newDevice.getBoard())) {
data.getDevice().getCustomData().put("foo", "bar"); assertTrue(listenerFired); listenerFired = false; data.getDevice().getCustomData().remove("foo"); assertTrue(listenerFired); listenerFired = false; data.setDevice(new Device()); assertTrue(listenerFired); listenerFired = false; data.getDevice().getCustomData().put("foo", "bar"); assertTrue(listenerFired); listenerFired = false; data.getDevice().getIntegrationConfig().setAmazonAwsSns(new IntegrationConfigItem()); assertTrue(listenerFired); listenerFired = false; data.getDevice().setIntegrationConfig(new IntegrationConfig()); assertTrue(listenerFired); listenerFired = false; data.getDevice().getIntegrationConfig().setAmazonAwsSns(new IntegrationConfigItem()); assertTrue(listenerFired); listenerFired = false; data.getDevice().setOsApiLevel(5);
private void doTest(String testFile) throws JSONException { String json = loadTextAssetAsString(TEST_DATA_DIR + testFile); InteractionCriteria criteria = new InteractionCriteria(json); Device device = new Device(); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), new EventData(), new Person(), device, new AppRelease()); Apptentive.DateTime dateTime = new Apptentive.DateTime(1000d); Apptentive.Version version = new Apptentive.Version(); version.setVersion("1.2.3"); device.getCustomData().put("number_5", 5); device.getCustomData().put("string_qwerty", "qwerty"); device.getCustomData().put("boolean_true", true); device.getCustomData().put("key_with_null_value", (String) null); device.getCustomData().put("datetime_1000", dateTime); device.getCustomData().put("version_1.2.3", version); assertTrue(criteria.isMet(fieldManager)); } }
public ConversationData() { this.localIdentifier = UUID.randomUUID().toString(); this.device = new Device(); this.person = new Person(); this.sdk = new Sdk(); this.appRelease = new AppRelease(); this.eventData = new EventData(); this.versionHistory = new VersionHistory(); }
@Override protected boolean execute(Conversation conversation) { conversation.getDevice().getCustomData().put(key, dateTime); return true; } }, "add custom device data");
public void setPushIntegration(int pushProvider, String token) { ApptentiveLog.v(CONVERSATION, "Setting push provider: %d with token %s", pushProvider, token); IntegrationConfig integrationConfig = getDevice().getIntegrationConfig(); IntegrationConfigItem item = new IntegrationConfigItem(); item.setToken(token); switch (pushProvider) { case Apptentive.PUSH_PROVIDER_APPTENTIVE: integrationConfig.setApptentive(item); break; case Apptentive.PUSH_PROVIDER_PARSE: integrationConfig.setParse(item); break; case Apptentive.PUSH_PROVIDER_URBAN_AIRSHIP: integrationConfig.setUrbanAirship(item); break; case Apptentive.PUSH_PROVIDER_AMAZON_AWS_SNS: integrationConfig.setAmazonAwsSns(item); break; default: ApptentiveLog.e(CONVERSATION, "Invalid pushProvider: %d", pushProvider); break; } }
private void doTest(String testFile) throws JSONException { String json = loadTextAssetAsString(TEST_DATA_DIR + testFile); InteractionCriteria criteria = new InteractionCriteria(json); Device device = new Device(); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), new EventData(), new Person(), device, new AppRelease()); device.getCustomData().put(" string_qwerty ", "qwerty"); device.getCustomData().put(" string with spaces ", "string with spaces"); /* TODO: It looks like we weren't trimming custom_data keys before storing them. What is the implication of doing that? We can't store a key under " key " and then retrieve it with "key" */ assertTrue(criteria.isMet(fieldManager)); } }
public Device clone() { Device clone = new Device(); clone.uuid = uuid; clone.osName = osName;
@Override protected boolean execute(Conversation conversation) { conversation.getDevice().getCustomData().put(key, value); return true; } }, "add custom device data");
if (deviceString != null) { com.apptentive.android.sdk.migration.v4_0_0.Device deviceOld = new com.apptentive.android.sdk.migration.v4_0_0.Device(deviceString); Device device = new Device(); device.setUuid(deviceOld.getUuid()); device.setOsName(deviceOld.getOsName()); device.setOsVersion(deviceOld.getOsVersion()); device.setOsBuild(deviceOld.getOsBuild()); String osApiLevel = deviceOld.getOsApiLevel(); if (!StringUtils.isNullOrEmpty(osApiLevel)) { device.setOsApiLevel(Integer.parseInt(osApiLevel)); device.setManufacturer(deviceOld.getManufacturer()); device.setModel(deviceOld.getModel()); device.setBoard(deviceOld.getBoard()); device.setProduct(deviceOld.getProduct()); device.setBrand(deviceOld.getBrand()); device.setCpu(deviceOld.getCpu()); device.setDevice(deviceOld.getDevice()); device.setCarrier(deviceOld.getCarrier()); device.setCurrentCarrier(deviceOld.getCurrentCarrier()); device.setNetworkType(deviceOld.getNetworkType()); device.setBuildType(deviceOld.getBuildType()); device.setBuildId(deviceOld.getBuildId()); device.setBootloaderVersion(deviceOld.getBootloaderVersion()); device.setRadioVersion(deviceOld.getRadioVersion()); device.setLocaleCountryCode(deviceOld.getLocaleCountryCode()); device.setLocaleLanguageCode(deviceOld.getLocaleLanguageCode()); device.setLocaleRaw(deviceOld.getLocaleRaw());
case custom_data: String customDataKey = tokens[2].trim(); CustomData customData = device.getCustomData(); if (customData != null) { String osVersion = device.getOsVersion(); if (osVersion == null) { osVersion = "0"; return ret; case os_api_level: return device.getOsApiLevel(); case board: return device.getBoard(); case bootloader_version: return device.getBootloaderVersion(); case brand: return device.getBrand(); case build_id: return device.getBuildId(); case build_type: return device.getBuildType(); case carrier: return device.getCarrier(); case cpu: return device.getCpu(); case current_carrier: return device.getCurrentCarrier(); case device:
@Test public void cornerCasesThatShouldBeTrue() throws JSONException { String json = loadTextAssetAsString(TEST_DATA_DIR + "testCornerCasesThatShouldBeTrue.json"); InteractionCriteria criteria = new InteractionCriteria(json); EventData eventData = new EventData(); Device device = new Device(); device.getCustomData().put("key_with_null_value", null); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), eventData, new Person(), device, new AppRelease()); assertNotNull("Criteria was null, but it shouldn't be.", criteria); assertTrue(criteria.isMet(fieldManager)); ApptentiveLog.e("Finished test."); }
@Test public void criteriaApplicationDebug() throws JSONException { AppRelease appRelease = AppReleaseManager.generateCurrentAppRelease(targetContext, null); String json = loadTextAssetAsString(TEST_DATA_DIR + "criteria/testCriteriaApplicationDebug.json"); json = json.replace("APPLICATION_DEBUG", Boolean.toString(appRelease.isDebug())); InteractionCriteria criteria = new InteractionCriteria(json); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), new EventData(), new Person(), new Device(), appRelease); assertTrue(criteria.isMet(fieldManager)); }
@Override protected boolean execute(Conversation conversation) { conversation.getDevice().getCustomData().remove(key); return true; } }, "remove custom device data");
@Test public void cornerCasesThatShouldBeFalse() throws JSONException { ApptentiveLog.e("Running test: testCornerCasesThatShouldBeFalse()\n\n"); String json = loadTextAssetAsString(TEST_DATA_DIR + "testCornerCasesThatShouldBeFalse.json"); InteractionCriteria criteria = new InteractionCriteria(json); EventData eventData = new EventData(); Device device = new Device(); device.getCustomData().put("key_with_null_value", null); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), eventData, new Person(), device, new AppRelease()); assertNotNull("Criteria was null, but it shouldn't be.", criteria); assertTrue(criteria.isMet(fieldManager)); ApptentiveLog.e("Finished test."); } }
@Test public void criteriaApplicationVersionCode() throws JSONException { AppRelease appRelease = AppReleaseManager.generateCurrentAppRelease(targetContext, null); String json = loadTextAssetAsString(TEST_DATA_DIR + "criteria/testCriteriaApplicationVersionCode.json"); json = json.replace("\"APPLICATION_VERSION_CODE\"", String.valueOf(appRelease.getVersionCode())); InteractionCriteria criteria = new InteractionCriteria(json); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), new EventData(), new Person(), new Device(), appRelease); assertTrue(criteria.isMet(fieldManager)); }
@Override protected boolean execute(Conversation conversation) { conversation.getDevice().getCustomData().put(key, version); return true; } }, "add custom device data");
@Test public void queriesAgainstSdk() throws JSONException { String json = loadTextAssetAsString(TEST_DATA_DIR + "testQueriesAgainstSdk.json"); InteractionCriteria criteria = new InteractionCriteria(json); Device device = new Device(); device.getCustomData().put("foo", "bar"); EventData eventData = new EventData(); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), eventData, new Person(), device, new AppRelease()); // 0 assertTrue(criteria.isMet(fieldManager)); // 1 eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "switch.code.point"); assertTrue(criteria.isMet(fieldManager)); // 2 eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "switch.code.point"); assertFalse(criteria.isMet(fieldManager)); } }
@Test public void criteriaApplicationVersionName() throws JSONException { AppRelease appRelease = AppReleaseManager.generateCurrentAppRelease(targetContext, null); String json = loadTextAssetAsString(TEST_DATA_DIR + "criteria/testCriteriaApplicationVersionName.json"); json = json.replace("APPLICATION_VERSION_NAME", appRelease.getVersionName()); InteractionCriteria criteria = new InteractionCriteria(json); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), new EventData(), new Person(), new Device(), appRelease); assertTrue(criteria.isMet(fieldManager)); }