/** * Creates a notification with a given name and user info and posts it to the receiver. */ public synchronized void postNotification(final String name, Object... args) { postNotification(name, ObjectUtils.toMap(args)); }
public <T> T getUserInfo(String key, Class<? extends T> valueClass) { return userInfo != null ? ObjectUtils.as(userInfo.get(key), valueClass) : null; }
public static void assertEquals(Object expected, Object actual) { if (imp != null && !ObjectUtils.equal(expected, actual)) { imp.assertFailed(StringUtils.format("Expected '%s' but was '%s'", expected, actual)); } }
public static void assertNotEquals(Object first, Object second) { if (imp != null && ObjectUtils.equal(first, second)) { imp.assertFailed(StringUtils.format("Expected '%s' and '%s' to differ, but they are the same.", first, second)); } }
public static void logException(Throwable e, Object... customData) { logException(e, ObjectUtils.toMap(customData)); }
private static @Nullable <T> T getSystemService(@NonNull Context context, @NonNull String name, @NonNull Class<? extends T> cls) { Object service = context.getSystemService(name); Assert.assertTrue(cls.isInstance(service), "Unexpected service class: %s", cls); return ObjectUtils.as(service, cls); } }
if (!(ObjectUtils.equal(currentVersionCode, previousVersionCode)) || !currentVersionName.equals(lastSeenVersionNameVersion.getVersion())) { appReleaseChanged = true;
public void logout() { checkConversationQueue(); if (activeConversation != null) { switch (activeConversation.getState()) { case LOGGED_IN: ApptentiveLog.d(CONVERSATION, "Ending active conversation."); EngagementModule.engageInternal(getContext(), activeConversation, "logout"); // Post synchronously to ensure logout payload can be sent before destroying the logged in conversation. ApptentiveNotificationCenter.defaultCenter().postNotification(NOTIFICATION_CONVERSATION_WILL_LOGOUT, ObjectUtils.toMap(NOTIFICATION_KEY_CONVERSATION, activeConversation)); activeConversation.destroy(); activeConversation.setState(LOGGED_OUT); handleConversationStateChange(activeConversation); setActiveConversation(null); ApptentiveInternal.dismissAllInteractions(); break; default: ApptentiveLog.w(CONVERSATION, "Attempted to logout() from Conversation, but the Active Conversation was not in LOGGED_IN state."); break; } } else { ApptentiveLog.w(CONVERSATION, "Attempted to logout(), but there was no Active Conversation."); } }
private static @Nullable KeyPair loadExistingWrapperKey(String keyAlias) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, UnrecoverableKeyException { KeyStore keyStore = KeyStore.getInstance(KEYSTORE_PROVIDER); keyStore.load(null); PrivateKey privateKey = ObjectUtils.as(keyStore.getKey(keyAlias, null), PrivateKey.class); if (privateKey == null) { return null; } Certificate certificate = keyStore.getCertificate(keyAlias); if (certificate == null) { return null; } PublicKey publicKey = certificate.getPublicKey(); if (publicKey == null) { return null; } return new KeyPair(publicKey, privateKey); }
notificationCenter.addObserver("notification2", o4, STRONG_REFERENCE); notificationCenter.postNotification("notification1", ObjectUtils.toMap("key1", "value1")); assertResult("observer1: notification1 {'key1':'value1'}", "observer2: notification1 {'key1':'value1'}"); notificationCenter.postNotification("notification2", ObjectUtils.toMap("key2", "value2")); assertResult("observer3: notification2 {'key2':'value2'}", "observer4: notification2 {'key2':'value2'}"); notificationCenter.removeObserver(o4); notificationCenter.postNotification("notification1", ObjectUtils.toMap("key1", "value1")); assertResult("observer2: notification1 {'key1':'value1'}"); notificationCenter.postNotification("notification2", ObjectUtils.toMap("key2", "value2")); assertResult("observer3: notification2 {'key2':'value2'}"); notificationCenter.postNotification("notification1", ObjectUtils.toMap("key1", "value1")); assertResult(); notificationCenter.postNotification("notification2", ObjectUtils.toMap("key2", "value2")); assertResult(); notificationCenter.postNotification("notification1", ObjectUtils.toMap("key1", "value1")); assertResult("observer1: notification1 {'key1':'value1'}", "observer2: notification1 {'key1':'value1'}"); notificationCenter.postNotification("notification2", ObjectUtils.toMap("key2", "value2")); assertResult("observer3: notification2 {'key2':'value2'}", "observer4: notification2 {'key2':'value2'}");
/** * Returns an index of the observer or its weak reference. * * @return -1 if not found */ private int indexOf(ApptentiveNotificationObserver observer) { for (int i = 0; i < observers.size(); ++i) { final ApptentiveNotificationObserver other = observers.get(i); if (other == observer) { return i; } final ObserverWeakReference otherReference = ObjectUtils.as(other, ObserverWeakReference.class); if (otherReference != null && otherReference.get() == observer) { return i; } } return -1; }
private @Nullable SecretKey loadExistingKey(String keyAlias) throws CertificateException, NoSuchAlgorithmException, IOException, UnrecoverableEntryException, KeyStoreException { KeyStore keyStore = KeyStore.getInstance(KEYSTORE_PROVIDER); keyStore.load(null); KeyStore.SecretKeyEntry secretKeyEntry = ObjectUtils.as(keyStore.getEntry(keyAlias, null), KeyStore.SecretKeyEntry.class); return secretKeyEntry != null ? secretKeyEntry.getSecretKey() : null; }
@Override protected boolean execute(Conversation conversation) { ApptentiveInternal instance = ObjectUtils.as(ApptentiveInternal.getInstance(), ApptentiveInternal.class); if (instance != null) { instance.tryUpdateApptimizeData(); return true; } return false; } }, "update Apptimize experiment data");
@Override protected boolean execute(Conversation conversation) { ApptentiveInternal instance = ObjectUtils.as(ApptentiveInternal.getInstance(), ApptentiveInternal.class); if (instance != null) { instance.tryUpdateApptimizeData(); return true; } return false; } }, "update Apptimize experiments data");
for (int i = 0; i < observers.size(); ++i) { ApptentiveNotificationObserver observer = observers.get(i); ObserverWeakReference observerRef = ObjectUtils.as(observer, ObserverWeakReference.class); if (observerRef == null || !observerRef.isReferenceLost()) { temp.add(observer); final ObserverWeakReference observerRef = ObjectUtils.as(observers.get(i), ObserverWeakReference.class); if (observerRef != null && observerRef.isReferenceLost()) { observers.remove(i);