/** * @return true if Apptimize SDK is integrated with the host app. */ public static boolean isApptimizeSDKAvailable() { return RuntimeUtils.classExists(CLASS_APPTIMIZE); }
public static Invocation fromClass(String name) throws InvocationException { if (name == null) { throw new IllegalArgumentException("Class name is null"); } Class<?> cls = RuntimeUtils.classForName(name); if (cls == null) { throw new InvocationException("Unable to find class '%s'", name); } return fromClass(cls); }
/** * Returns <code>true</code> is the app is running in a debug mode */ public static boolean isAppDebuggable(Context context) { return getApplicationInfo(context).isDebuggable(); }
return "time at install"; case version_code: return StringUtils.format("time at install for version code '%d'", RuntimeUtils.getAppVersionCode(context)); case version_name: return StringUtils.format("time at install for version name '%s'", RuntimeUtils.getAppVersionName(context)); return StringUtils.format("number of invokes for interaction '%s'", interactionId); case version_code: int appVersionCode = RuntimeUtils.getAppVersionCode(context); return StringUtils.format("number of invokes for interaction '%s' for version code '%d'", interactionId, appVersionCode); case version_name: String appVersionName = RuntimeUtils.getAppVersionName(context); return StringUtils.format("number of invokes for interaction '%s' for version name '%s'", interactionId, appVersionName); default: return StringUtils.format("number of invokes for event '%s'", eventLabel); case version_code: int appVersionCode = RuntimeUtils.getAppVersionCode(context); return StringUtils.format("number of invokes for event '%s' for version code '%d'", eventLabel, appVersionCode); case version_name: String appVersionName = RuntimeUtils.getAppVersionName(context); return StringUtils.format("number of invokes for event '%s' for version name '%s'", eventLabel, appVersionName); default:
private static void overrideMainQueue(final MockDispatchQueue queue) { try { overrideStaticFinalField(findHolderClass(DispatchQueue.class.getDeclaredClasses()), "MAIN_QUEUE", queue); overrideStaticFinalField(DispatchQueue.class, "MAIN_QUEUE_CHECKER", new DispatchQueue.MainQueueChecker() { @Override public boolean isMainQueue() { return queue.indentifyAsMainQueue; } }); } catch (Exception e) { throw new AssertionError(e); } }
boolean debuggable = RuntimeUtils.isAppDebuggable(getContext()); if (!debuggable) { ApptentiveLog.d(APP_CONFIGURATION, "Can't fetch app configuration: the old configuration is still valid");
public static void overrideStaticFinalField(Class<?> cls, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException { Field instanceField = cls.getDeclaredField(fieldName); instanceField.setAccessible(true); Field modifiersField = getFieldModifiers(); modifiersField.setAccessible(true); modifiersField.setInt(instanceField, instanceField.getModifiers() & ~Modifier.FINAL); instanceField.set(null, value); }
protected static void registerSensitiveKeys(Class<? extends JsonPayload> cls) { List<Field> fields = RuntimeUtils.listFields(cls, new RuntimeUtils.FieldFilter() { @Override public boolean accept(Field field) { return Modifier.isStatic(field.getModifiers()) && // static fields field.getAnnotation(SensitiveDataKey.class) != null && // marked as 'sensitive' field.getType().equals(String.class); // with type of String } }); if (fields.size() > 0) { List<String> keys = new ArrayList<>(fields.size()); try { for (Field field : fields) { field.setAccessible(true); String value = (String) field.get(null); keys.add(value); } SENSITIVE_KEYS_LOOKUP.put(cls, keys); } catch (Exception e) { ApptentiveLog.e(e, "Exception while registering sensitive keys"); logException(e); } } }
if (entry.getVersionCode() == RuntimeUtils.getAppVersionCode(ApptentiveInternal.getInstance().getApplicationContext())) { return new Apptentive.DateTime(entry.getTimestamp()); Apptentive.Version currentVersionName = new Apptentive.Version(); entryVersionName.setVersion(entry.getVersionName()); currentVersionName.setVersion(RuntimeUtils.getAppVersionName(ApptentiveInternal.getInstance().getApplicationContext())); if (entryVersionName.equals(currentVersionName)) { return new Apptentive.DateTime(entry.getTimestamp());
@Override protected void setUp() throws Exception { super.setUp(); try { // main queue overrideMainQueue(true); // conversation queue RuntimeUtils.overrideStaticFinalField(findHolderClass(ApptentiveHelper.class.getDeclaredClasses()), "CONVERSATION_QUEUE", new MockDispatchQueue(true)); } catch (Exception e) { throw new AssertionError(e); } }
if (cacheExpired || RuntimeUtils.isAppDebuggable(context)) { ApptentiveHttpClient httpClient = ApptentiveInternal.getInstance().getApptentiveHttpClient(); HttpRequest existing = httpClient.findRequest(TAG_FETCH_INTERACTIONS_REQUEST);
return versionHistory.getTimeAtInstallTotal(); case version_code: return versionHistory.getTimeAtInstallForVersionCode(RuntimeUtils.getAppVersionCode(context)); case version_name: return versionHistory.getTimeAtInstallForVersionName(RuntimeUtils.getAppVersionName(context)); return new BigDecimal(eventData.getInteractionCountTotal(interactionId)); case version_code: Integer appVersionCode = RuntimeUtils.getAppVersionCode(context); return new BigDecimal(eventData.getInteractionCountForVersionCode(interactionId, appVersionCode)); case version_name: String appVersionName = RuntimeUtils.getAppVersionName(context); return new BigDecimal(eventData.getInteractionCountForVersionName(interactionId, appVersionName)); default: return new BigDecimal(eventData.getEventCountTotal(eventLabel)); case version_code: Integer appVersionCode = RuntimeUtils.getAppVersionCode(context); return new BigDecimal(eventData.getEventCountForVersionCode(eventLabel, appVersionCode)); case version_name: String appVersionName = RuntimeUtils.getAppVersionName(context); return new BigDecimal(eventData.getEventCountForVersionName(eventLabel, appVersionName)); default:
public static String getAppVersionName(Context context) { return getApplicationInfo(context).getVersionName(); }
public static int getAppVersionCode(Context context) { return getApplicationInfo(context).getVersionCode(); }
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; }