public static AppRelease generateCurrentAppRelease(Context context, ApptentiveInternal apptentiveInternal) { AppRelease appRelease = new AppRelease(); String appPackageName = context.getPackageName(); int themeOverrideResId = context.getResources().getIdentifier("ApptentiveThemeOverride", "style", appPackageName); ApplicationInfo applicationInfo = RuntimeUtils.getApplicationInfo(context); appRelease.setAppStore(Util.getInstallerPackageName(context)); appRelease.setDebug(applicationInfo.isDebuggable()); appRelease.setIdentifier(appPackageName); if (apptentiveInternal != null) { appRelease.setInheritStyle(apptentiveInternal.isAppUsingAppCompatTheme()); } appRelease.setOverrideStyle(themeOverrideResId != 0); appRelease.setTargetSdkVersion(String.valueOf(applicationInfo.getTargetSdkVersion())); appRelease.setType("android"); appRelease.setVersionCode(applicationInfo.getVersionCode()); appRelease.setVersionName(applicationInfo.getVersionName()); return appRelease; }
public static AppReleasePayload getPayload(AppRelease appRelease) { AppReleasePayload ret = new AppReleasePayload(); if (appRelease == null) { return ret; } ret.setAppStore(appRelease.getAppStore()); ret.setDebug(appRelease.isDebug()); ret.setIdentifier(appRelease.getIdentifier()); ret.setInheritStyle(appRelease.isInheritStyle()); ret.setOverrideStyle(appRelease.isOverrideStyle()); ret.setTargetSdkVersion(appRelease.getTargetSdkVersion()); ret.setType(appRelease.getType()); ret.setVersionCode(appRelease.getVersionCode()); ret.setVersionName(appRelease.getVersionName()); return ret; }
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(); }
switch (applicationQuery) { case version_code: { return appRelease.getVersionCode(); ret.setVersion(appRelease.getVersionName()); return ret; return appRelease.isDebug();
final int currentVersionCode = appRelease.getVersionCode(); final String currentVersionName = appRelease.getVersionName();
public String getApplicationVersionName() { return appRelease.getVersionName(); }
public boolean isApptentiveDebuggable() { return appRelease.isDebug(); }
public int getApplicationVersionCode() { return appRelease.getVersionCode(); }
@Test public void defaultValues() throws JSONException { String json = loadTextAssetAsString(TEST_DATA_DIR + "testDefaultValues.json"); InteractionCriteria criteria = new InteractionCriteria(json); FieldManager fieldManager = new FieldManager(targetContext, new VersionHistory(), new EventData(), new Person(), new Device(), new AppRelease()); assertNotNull("Criteria was null, but it shouldn't be.", criteria); assertTrue(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)); }
ApptentiveLog.v("Application Info:\n\tApptentive Key: %s\n\tApptentive Key: %s\n\tDebuggable APK: %b\n\tDefault locale: %s", apptentiveKey, apptentiveSignature, appRelease.isDebug(), Locale.getDefault()); return bRet;
@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)); }
public static com.apptentive.android.sdk.model.SdkAndAppReleasePayload getPayload(Sdk sdk, AppRelease appRelease) { com.apptentive.android.sdk.model.SdkAndAppReleasePayload ret = new com.apptentive.android.sdk.model.SdkAndAppReleasePayload(); if (appRelease == null) { return ret; } // sdk data ret.setAuthorEmail(sdk.getAuthorEmail()); ret.setAuthorName(sdk.getAuthorName()); ret.setDistribution(sdk.getDistribution()); ret.setDistributionVersion(sdk.getDistributionVersion()); ret.setPlatform(sdk.getPlatform()); ret.setProgrammingLanguage(sdk.getProgrammingLanguage()); ret.setVersion(sdk.getVersion()); // app release data ret.setAppStore(appRelease.getAppStore()); ret.setDebug(appRelease.isDebug()); ret.setIdentifier(appRelease.getIdentifier()); ret.setInheritStyle(appRelease.isInheritStyle()); ret.setOverrideStyle(appRelease.isOverrideStyle()); ret.setTargetSdkVersion(appRelease.getTargetSdkVersion()); ret.setType(appRelease.getType()); ret.setVersionCode(appRelease.getVersionCode()); ret.setVersionName(appRelease.getVersionName()); return ret; } }
private void migrateAppRelease() { String appReleaseString = prefs.getString(Constants.PREF_KEY_APP_RELEASE, null); if (appReleaseString != null) { try { com.apptentive.android.sdk.migration.v4_0_0.AppRelease appReleaseOld = new com.apptentive.android.sdk.migration.v4_0_0.AppRelease(appReleaseString); AppRelease appRelease = new AppRelease(); appRelease.setAppStore(appReleaseOld.getAppStore()); appRelease.setDebug(appReleaseOld.getDebug()); appRelease.setIdentifier(appReleaseOld.getIdentifier()); appRelease.setInheritStyle(appReleaseOld.getInheritStyle()); appRelease.setOverrideStyle(appReleaseOld.getOverrideStyle()); appRelease.setTargetSdkVersion(appReleaseOld.getTargetSdkVersion()); appRelease.setType(appReleaseOld.getType()); appRelease.setVersionCode(appReleaseOld.getVersionCode()); appRelease.setVersionName(appReleaseOld.getVersionName()); conversation.setAppRelease(appRelease); } catch (Exception e) { ApptentiveLog.e(CONVERSATION, e, "Error migrating AppRelease."); logException(e); } } }
@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 upgradeMessageOnVersionName() throws JSONException { AppRelease appRelease = AppReleaseManager.generateCurrentAppRelease(targetContext, null); String json = loadTextAssetAsString(TEST_DATA_DIR + "payloads/upgradeMessageOnVersionName.json") .replace("APPLICATION_VERSION_NAME", appRelease.getVersionName()); InteractionCriteria criteria = new InteractionCriteria(json); VersionHistory versionHistory = new VersionHistory(); EventData eventData = new EventData(); FieldManager fieldManager = new FieldManager(targetContext, versionHistory, eventData, new Person(), new Device(), appRelease); versionHistory.updateVersionHistory(Util.currentTimeSeconds(), versionCode, versionName); eventData.storeEventForCurrentAppVersion(Util.currentTimeSeconds(), versionCode, versionName, "app.launch"); // Test version targeted UpgradeMessage // Saw this build too long ago. ApptentiveLog.e("ONE"); versionHistory.clear(); versionHistory.updateVersionHistory(Util.currentTimeSeconds() - 1000000, 3, "1.0"); versionHistory.updateVersionHistory(Util.currentTimeSeconds() - 600000, 4, "2.0.0"); assertFalse(criteria.isMet(fieldManager)); // Haven't upgraded ApptentiveLog.e("TWO"); versionHistory.clear(); versionHistory.updateVersionHistory(Util.currentTimeSeconds() - 499500, 4, "2.0.0"); assertFalse(criteria.isMet(fieldManager)); // Just right ApptentiveLog.e("THREE"); versionHistory.clear(); versionHistory.updateVersionHistory(Util.currentTimeSeconds() - 1000000, 3, "1.0"); versionHistory.updateVersionHistory(Util.currentTimeSeconds() - 499500, 4, "2.0.0"); assertTrue(criteria.isMet(fieldManager)); }
@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)); }
@Test public void upgradeMessageOnVersionCode() throws JSONException { AppRelease appRelease = AppReleaseManager.generateCurrentAppRelease(targetContext, null); String json = loadTextAssetAsString(TEST_DATA_DIR + "payloads/upgradeMessageOnVersionCode.json") .replace("\"APPLICATION_VERSION_CODE\"", String.valueOf(appRelease.getVersionCode())); InteractionCriteria criteria = new InteractionCriteria(json); VersionHistory versionHistory = new VersionHistory(); FieldManager fieldManager = new FieldManager(targetContext, versionHistory, new EventData(), new Person(), new Device(), appRelease); versionHistory.updateVersionHistory(Util.currentTimeSeconds(), versionCode, versionName); // Test version targeted UpgradeMessage // Saw this build too long ago. ApptentiveLog.e("ONE"); versionHistory.clear(); versionHistory.updateVersionHistory(Util.currentTimeSeconds() - 1000000, 1, "1.0"); versionHistory.updateVersionHistory(Util.currentTimeSeconds() - 600000, versionCode, "2.0.0"); ApptentiveLog.e("Current time: %f", Util.currentTimeSeconds()); assertFalse(criteria.isMet(fieldManager)); // Haven't upgraded ApptentiveLog.e("TWO"); versionHistory.clear(); versionHistory.updateVersionHistory(Util.currentTimeSeconds() - 499500, versionCode, "2.0.0"); assertFalse(criteria.isMet(fieldManager)); // Just right ApptentiveLog.e("THREE"); versionHistory.clear(); versionHistory.updateVersionHistory(Util.currentTimeSeconds() - 1000000, 1, "1.0"); versionHistory.updateVersionHistory(Util.currentTimeSeconds() - 499500, versionCode, "2.0.0"); assertTrue(criteria.isMet(fieldManager)); }
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)); } }
@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."); } }