diff --git a/.travis.yml b/.travis.yml index eb2937ecb..cf1006be7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,6 @@ cache: before_install: - ./travis/scripts/extract_private_build_config.sh - - ./travis/scripts/install_android_ndk.sh - export PATH=$HOME/.local/bin:$PATH - pip install -r ./travis/configs/requirements.txt --user diff --git a/gradle.properties b/gradle.properties index 9928ecb2b..63b5f2ebb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,5 +15,4 @@ # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -android.useDeprecatedNdk=true \ No newline at end of file +# org.gradle.parallel=true \ No newline at end of file diff --git a/twidere/build.gradle b/twidere/build.gradle index 224a2bbbb..5e278d742 100644 --- a/twidere/build.gradle +++ b/twidere/build.gradle @@ -27,10 +27,6 @@ android { versionName "0.3.0" multiDexEnabled true - ndk { - ldLibs 'log' - } - buildConfigField 'boolean', 'ENABLE_MEDIA_VIEWER', 'Boolean.parseBoolean("true")' } @@ -111,6 +107,7 @@ dependencies { compile 'com.github.mariotaku:PickNCrop:0.9.2' compile 'com.github.mariotaku.RestFu:library:0.9.11' compile 'com.github.mariotaku.RestFu:okhttp:0.9.11' + compile 'com.github.mariotaku:InetAddressJni:0.9.1' compile 'com.diogobernardino:williamchart:2.1' compile 'com.lnikkila:extendedtouchview:0.1.0' compile 'com.google.dagger:dagger:2.0.2' diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/net/InetAddressUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/net/InetAddressUtils.java deleted file mode 100644 index 4dbb7e1d6..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/util/net/InetAddressUtils.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - * - */ -package org.mariotaku.twidere.util.net; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import java.net.InetAddress; - -/** - * A collection of utilities relating to InetAddresses. - * - * @since 4.0 - */ -public class InetAddressUtils { - - static { - System.loadLibrary("twidere"); - } - - private InetAddressUtils() { - throw new AssertionError("Trying to instantiate this class"); - } - - /** - * @param input IP address in string - * @return type corresponding to <sys/socket.h> - */ - public native static int getInetAddressType(final String input); - - @Nullable - public native static InetAddress getResolvedIPAddress(@Nullable final String host, @NonNull final String address); -} \ No newline at end of file diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/net/SystemHosts.java b/twidere/src/main/java/org/mariotaku/twidere/util/net/SystemHosts.java index 4159b5351..3bf906da7 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/net/SystemHosts.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/net/SystemHosts.java @@ -22,6 +22,7 @@ package org.mariotaku.twidere.util.net; import android.support.annotation.NonNull; import android.text.TextUtils; +import org.mariotaku.inetaddrjni.library.InetAddressUtils; import org.mariotaku.twidere.util.Utils; import java.io.BufferedReader; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/net/TwidereDns.java b/twidere/src/main/java/org/mariotaku/twidere/util/net/TwidereDns.java index f1adaab57..5afab9a6b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/net/TwidereDns.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/net/TwidereDns.java @@ -33,6 +33,7 @@ import com.squareup.okhttp.Dns; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; +import org.mariotaku.inetaddrjni.library.InetAddressUtils; import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.util.SharedPreferencesWrapper; diff --git a/twidere/src/main/jni/inetaddressutils.c b/twidere/src/main/jni/inetaddressutils.c deleted file mode 100644 index f9a807062..000000000 --- a/twidere/src/main/jni/inetaddressutils.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include - -JNIEXPORT jint JNICALL -Java_org_mariotaku_twidere_util_net_InetAddressUtils_getInetAddressType(JNIEnv *env, jclass type, - jstring input_) { - if (input_ == NULL) return AF_UNSPEC; - const char *input = (*env)->GetStringUTFChars(env, input_, 0); - - struct sockaddr addr; - - int addr_type = AF_UNSPEC; - if (inet_pton(AF_INET, input, &addr) > 0) { - addr_type = AF_INET; - } else if (inet_pton(AF_INET6, input, &addr) > 0) { - addr_type = AF_INET6; - } - (*env)->ReleaseStringUTFChars(env, input_, input); - return addr_type; -} - -JNIEXPORT jobject JNICALL -Java_org_mariotaku_twidere_util_net_InetAddressUtils_getResolvedIPAddress(JNIEnv *env, jclass type, - jstring host_, - jstring address_) { - if (address_ == NULL) return NULL; - - const char *address = (*env)->GetStringUTFChars(env, address_, 0); - - jclass addressClass = (*env)->FindClass(env, "java/net/InetAddress"); - jmethodID getByAddressMethod = (*env)->GetStaticMethodID(env, addressClass, "getByAddress", - "(Ljava/lang/String;[B)Ljava/net/InetAddress;"); - - void *bin_addr = malloc(16); - memset(bin_addr, 0, 16); - - jbyteArray data = NULL; - if (inet_pton(AF_INET, address, bin_addr) > 0) { - data = (*env)->NewByteArray(env, 4); - (*env)->SetByteArrayRegion(env, data, 0, 4, (jbyte *) bin_addr); - } else if (inet_pton(AF_INET6, address, bin_addr) > 0) { - data = (*env)->NewByteArray(env, 16); - (*env)->SetByteArrayRegion(env, data, 0, 16, (jbyte *) bin_addr); - } - - (*env)->ReleaseStringUTFChars(env, address_, address); - free(bin_addr); - - if (data) { - return (*env)->CallStaticObjectMethod(env, addressClass, getByAddressMethod, host_, data); - } - - return NULL; - -} \ No newline at end of file