Browse Source

update gradle, add NetworkCallback support

Signed-off-by: R4SAS <r4sas@i2pmail.org>
pull/18/head
R4SAS 4 years ago
parent
commit
a25d24146a
  1. 15
      app/build.gradle
  2. 2
      app/jni/i2pd
  3. 4
      app/src/main/AndroidManifest.xml
  4. 42
      app/src/main/java/org/purplei2p/i2pd/I2PDActivity.java
  5. 8
      build.gradle
  6. 4
      gradle/wrapper/gradle-wrapper.properties

15
app/build.gradle

@ -8,21 +8,20 @@ dependencies { @@ -8,21 +8,20 @@ dependencies {
android {
compileSdkVersion 29
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "org.purplei2p.i2pd"
targetSdkVersion 29
minSdkVersion 14
versionCode 23300
versionName "2.33.0-63-g2648f1ba"
versionName "2.33.0-67-gb7ebb3ea"
setProperty("archivesBaseName", archivesBaseName + "-" + versionName)
ndk {
abiFilters 'armeabi-v7a'
abiFilters 'x86'
abiFilters 'arm64-v8a'
abiFilters 'x86_64'
abiFilters "armeabi-v7a"
abiFilters "x86"
abiFilters "arm64-v8a"
abiFilters "x86_64"
}
externalNativeBuild {
@ -45,7 +44,7 @@ android { @@ -45,7 +44,7 @@ android {
signingConfigs {
release {
storeFile file('i2pdapk.jks')
storeFile file("i2pdapk.jks")
storePassword "android"
keyAlias "i2pdapk"
keyPassword "android"
@ -64,7 +63,7 @@ android { @@ -64,7 +63,7 @@ android {
externalNativeBuild {
ndkBuild {
path './jni/Android.mk'
path "${rootProject.projectDir}/app/jni/Android.mk"
}
}

2
app/jni/i2pd

@ -1 +1 @@ @@ -1 +1 @@
Subproject commit 2648f1ba89d5032262a72ca8b2d2d8a70e441b9a
Subproject commit b7ebb3ea3d1b275e567c4cd015749355911f3f60

4
app/src/main/AndroidManifest.xml

@ -20,7 +20,9 @@ @@ -20,7 +20,9 @@
android:usesCleartextTraffic="true"
>
<receiver android:name=".NetworkStateChangeReceiver">
<receiver
android:name=".NetworkStateChangeReceiver"
android:label="NetworkChangeReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>

42
app/src/main/java/org/purplei2p/i2pd/I2PDActivity.java

@ -15,6 +15,7 @@ import java.util.TimerTask; @@ -15,6 +15,7 @@ import java.util.TimerTask;
import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
@ -25,6 +26,10 @@ import android.content.ServiceConnection; @@ -25,6 +26,10 @@ import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.net.Uri;
import android.os.Bundle;
import android.os.Build;
@ -41,6 +46,7 @@ import android.widget.Toast; @@ -41,6 +46,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@ -63,6 +69,7 @@ public class I2PDActivity extends Activity { @@ -63,6 +69,7 @@ public class I2PDActivity extends Activity {
private TextView textView;
private boolean assetsCopied;
private NetworkStateCallback networkCallback;
private String i2pdpath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/i2pd/";
//private ConfigParser parser = new ConfigParser(i2pdpath); // TODO:
@ -116,7 +123,7 @@ public class I2PDActivity extends Activity { @@ -116,7 +123,7 @@ public class I2PDActivity extends Activity {
daemonStateUpdatedListener.daemonStateUpdate();
// request permissions
if (Build.VERSION.SDK_INT >= 23) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
@ -137,6 +144,10 @@ public class I2PDActivity extends Activity { @@ -137,6 +144,10 @@ public class I2PDActivity extends Activity {
}
openBatteryOptimizationDialogIfNeeded();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
registerNetworkCallback();
}
}
@Override
@ -243,7 +254,7 @@ public class I2PDActivity extends Activity { @@ -243,7 +254,7 @@ public class I2PDActivity extends Activity {
}
private boolean isBatteryOptimizationsOpenOsDialogApiAvailable() {
return android.os.Build.VERSION.SDK_INT >= 23;
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}
@Override
@ -624,6 +635,33 @@ public class I2PDActivity extends Activity { @@ -624,6 +635,33 @@ public class I2PDActivity extends Activity {
return "show_battery_optimization" + (device == null ? "" : device);
}
@TargetApi(Build.VERSION_CODES.M)
private void registerNetworkCallback() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkRequest request = new NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)
.build();
networkCallback = new NetworkStateCallback();
connectivityManager.registerNetworkCallback(request, networkCallback);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private final class NetworkStateCallback extends ConnectivityManager.NetworkCallback {
@Override
public void onAvailable(Network network) {
super.onAvailable(network);
I2PD_JNI.onNetworkStateChanged(true);
Log.i(TAG, "NetworkCallback.onAvailable");
}
@Override
public void onLost(Network network) {
super.onLost(network);
I2PD_JNI.onNetworkStateChanged(false);
Log.i(TAG, " NetworkCallback.onLost");
}
}
private void quit() {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

8
build.gradle

@ -1,18 +1,20 @@ @@ -1,18 +1,20 @@
buildscript {
repositories {
mavenCentral()
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:4.1.0'
}
}
allprojects {
repositories {
mavenCentral()
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

4
gradle/wrapper/gradle-wrapper.properties vendored

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
#Fri Jun 12 07:37:19 MSK 2020
#Thu Oct 15 17:35:03 MSK 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

Loading…
Cancel
Save