JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_setAcceptableAdsEnabled(JNIEnv *pEnv, jobject, jboolean enabled)
{
    D(D_WARN, "setAcceptableAdsEnabled()");
    try
    {
        const std::string surl = filterEngine->GetPref("subscriptions_exceptionsurl")->AsString();
        AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription(surl);
        if (enabled == JNI_TRUE)
        {
            subscription->AddToList();
        }
        else if (subscription->IsListed())
        {
            subscription->RemoveFromList();
        }
    }
    catch (const std::exception& e)
    {
        ThrowJavaException(pEnv, e);
    }
    catch (...)
    {
        ThrowJavaException(pEnv);
    }
}
예제 #2
0
TEST_F(FilterEngineTest, SubscriptionProperties)
{
  AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo");

  ASSERT_TRUE(subscription->GetProperty("stringFoo")->IsUndefined());
  ASSERT_TRUE(subscription->GetProperty("intFoo")->IsUndefined());
  ASSERT_TRUE(subscription->GetProperty("boolFoo")->IsUndefined());

  subscription->SetProperty("stringFoo", "y");
  subscription->SetProperty("intFoo", 24);
  subscription->SetProperty("boolFoo", true);
  ASSERT_EQ("y", subscription->GetProperty("stringFoo")->AsString());
  ASSERT_EQ(24, subscription->GetProperty("intFoo")->AsInt());
  ASSERT_TRUE(subscription->GetProperty("boolFoo")->AsBool());
}
void UpdateSubscriptionStatus(const AdblockPlus::SubscriptionPtr subscription)
{
    D(D_WARN, "UpdateSubscriptionStatus()");

    std::string downloadStatus = subscription->GetProperty("downloadStatus")->IsNull() ? "" : subscription->GetProperty("downloadStatus")->AsString();
    int64_t lastDownload = subscription->GetProperty("lastDownload")->AsInt();

    std::string status = "synchronize_never";
    int64_t time = 0;

    if (subscription->IsUpdating())
    {
        status = "synchronize_in_progress";
    }
    else if (!downloadStatus.empty() && downloadStatus != "synchronize_ok")
    {
        status = downloadStatus;
    }
    else if (lastDownload > 0)
    {
        time = lastDownload;
        status = "synchronize_last_at";
    }

    JNIEnv* jniEnv = NULL;
    int stat = globalJvm->GetEnv((void **)&jniEnv, JNI_VERSION_1_6);
    if (stat == JNI_EDETACHED)
    {
        if (globalJvm->AttachCurrentThread(&jniEnv, NULL) != 0)
            throw std::runtime_error("Failed to get JNI environment");
    }

    jstring jUrl = jniEnv->NewStringUTF(subscription->GetProperty("url")->AsString().c_str());
    jstring jStatus = jniEnv->NewStringUTF(status.c_str());
    jlong jTime = time * 1000;

    static jclass cls = jniEnv->GetObjectClass(jniObject);
    static jmethodID mid = jniEnv->GetMethodID(cls, "onFilterChanged", "(Ljava/lang/String;Ljava/lang/String;J)V");
    if (mid)
        jniEnv->CallVoidMethod(jniObject, mid, jUrl, jStatus, jTime);
    jniEnv->DeleteLocalRef(jUrl);
    jniEnv->DeleteLocalRef(jStatus);

    if (stat == JNI_EDETACHED)
        globalJvm->DetachCurrentThread();
}
JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_refreshSubscription(JNIEnv *pEnv, jobject, jstring url)
{
    D(D_WARN, "refreshSubscription()");
    try
    {
        const std::string surl = GetString(pEnv, url);
        AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription(surl);
        subscription->UpdateFilters();
    }
    catch (const std::exception& e)
    {
        ThrowJavaException(pEnv, e);
    }
    catch (...)
    {
        ThrowJavaException(pEnv);
    }
}
예제 #5
0
TEST_F(FilterEngineTest, AddRemoveSubscriptions)
{
  ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
  AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo");
  ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
  ASSERT_FALSE(subscription->IsListed());
  subscription->AddToList();
  ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
  ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]);
  ASSERT_TRUE(subscription->IsListed());
  subscription->AddToList();
  ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
  ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]);
  ASSERT_TRUE(subscription->IsListed());
  subscription->RemoveFromList();
  ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
  ASSERT_FALSE(subscription->IsListed());
  subscription->RemoveFromList();
  ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
  ASSERT_FALSE(subscription->IsListed());
}
JNIEXPORT void JNICALL Java_org_adblockplus_android_ABPEngine_removeSubscription(JNIEnv *pEnv, jobject, jstring url)
{
    D(D_WARN, "removeSubscription()");
    try
    {
        const std::string surl = GetString(pEnv, url);
        AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription(surl);
        if (subscription->IsListed())
        {
            subscription->RemoveFromList();
        }
    }
    catch (const std::exception& e)
    {
        ThrowJavaException(pEnv, e);
    }
    catch (...)
    {
        ThrowJavaException(pEnv);
    }
}
예제 #7
0
TEST_F(FilterEngineTest, AddRemoveSubscriptions)
{
  // There should be only the default subscription initially
  ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
  AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo");
  ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
  ASSERT_FALSE(subscription->IsListed());
  subscription->AddToList();
  ASSERT_EQ(2u, filterEngine->GetListedSubscriptions().size());
  ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[1]);
  ASSERT_TRUE(subscription->IsListed());
  subscription->AddToList();
  ASSERT_EQ(2u, filterEngine->GetListedSubscriptions().size());
  ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[1]);
  ASSERT_TRUE(subscription->IsListed());
  subscription->RemoveFromList();
  ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
  ASSERT_FALSE(subscription->IsListed());
  subscription->RemoveFromList();
  ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
  ASSERT_FALSE(subscription->IsListed());
}
예제 #8
0
TEST_F(FilterEngineTest, SubscriptionUpdates)
{
  AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo");
  ASSERT_FALSE(subscription->IsUpdating());
  subscription->UpdateFilters();
}