summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2017-06-11 14:49:22 +0200
committerArne Schwabe <arne@rfc2549.org>2017-06-11 14:49:22 +0200
commit0643b6c379c22ee8aa68809f93a0d29937209ce4 (patch)
tree78116c9f7a53d4819e6dfd350d735e96855bbf8a
parent3f54f3792fa043241e52520fc1a1040843b9b14d (diff)
Android O changes
-rw-r--r--main/build.gradle6
-rw-r--r--main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java8
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java6
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java44
4 files changed, 36 insertions, 28 deletions
diff --git a/main/build.gradle b/main/build.gradle
index f3f4e0e7..9e28933b 100644
--- a/main/build.gradle
+++ b/main/build.gradle
@@ -23,12 +23,12 @@ dependencies {
}
android {
- compileSdkVersion 25
- buildToolsVersion '25.0.3'
+ compileSdkVersion 26
+ buildToolsVersion '26.0.0'
defaultConfig {
minSdkVersion 14
- targetSdkVersion 25
+ targetSdkVersion 26
versionCode = 149
versionName = "0.6.69"
}
diff --git a/main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java b/main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java
index eadc1d9f..5b06c833 100644
--- a/main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java
+++ b/main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java
@@ -37,6 +37,7 @@ public class MainActivity extends BaseActivity {
private ViewPager mPager;
private ScreenSlidePagerAdapter mPagerAdapter;
private SlidingTabLayout mSlidingTabLayout;
+ private TabBarView mTabs;
protected void onCreate(android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -71,8 +72,8 @@ public class MainActivity extends BaseActivity {
mPagerAdapter.addTab(R.string.about, AboutFragment.class);
mPager.setAdapter(mPagerAdapter);
- TabBarView tabs = (TabBarView) findViewById(R.id.sliding_tabs);
- tabs.setViewPager(mPager);
+ mTabs = (TabBarView) findViewById(R.id.sliding_tabs);
+ mTabs.setViewPager(mPager);
}
private static final String FEATURE_TELEVISION = "android.hardware.type.television";
@@ -94,8 +95,9 @@ public class MainActivity extends BaseActivity {
super.onResume();
if (getIntent()!=null) {
String page = getIntent().getStringExtra("PAGE");
- if ("graph".equals(page))
+ if ("graph".equals(page)) {
mPager.setCurrentItem(1);
+ }
setIntent(null);
}
}
diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
index 9c589fbc..9042ddba 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java
@@ -68,6 +68,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
private static final String PAUSE_VPN = "de.blinkt.openvpn.PAUSE_VPN";
private static final String RESUME_VPN = "de.blinkt.openvpn.RESUME_VPN";
private static final int OPENVPN_STATUS = 1;
+ private static final String NOTIFICATION_CHANNEL_ID="openvpn";
private static boolean mNotificationAlwaysVisible = false;
private final Vector<String> mDnslist = new Vector<>();
private final NetworkSpace mRoutes = new NetworkSpace();
@@ -122,7 +123,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
int unit = speed ? 1000 : 1024;
- int exp = Math.min((int) (Math.log(bytes) / Math.log(unit)), 3);
+ int exp = Math.max(0, Math.min((int) (Math.log(bytes) / Math.log(unit)), 3));
float bytesUnit = Math.round(bytes / Math.pow(unit, exp));
@@ -228,6 +229,9 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
lpNotificationExtras(nbuilder);
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ nbuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
+
if (tickerText != null && !tickerText.equals(""))
nbuilder.setTicker(tickerText);
diff --git a/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java b/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
index bc03db25..f15515f3 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java
@@ -6,6 +6,7 @@
package de.blinkt.openvpn.core;
import android.annotation.TargetApi;
+import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
@@ -26,7 +27,6 @@ public class VPNLaunchHelper {
private static final String OVPNCONFIGFILE = "android.conf";
-
private static String writeMiniVPN(Context context) {
String[] abis;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
@@ -38,10 +38,10 @@ public class VPNLaunchHelper {
String nativeAPI = NativeUtils.getNativeAPI();
if (!nativeAPI.equals(abis[0])) {
VpnStatus.logWarning(R.string.abi_mismatch, Arrays.toString(abis), nativeAPI);
- abis = new String[] {nativeAPI};
+ abis = new String[]{nativeAPI};
}
- for (String abi: abis) {
+ for (String abi : abis) {
File vpnExecutable = new File(context.getCacheDir(), "c_" + getMiniVPNExecutableName() + "." + abi);
if ((vpnExecutable.exists() && vpnExecutable.canExecute()) || writeMiniVPNBinary(context, abi, vpnExecutable)) {
@@ -50,24 +50,22 @@ public class VPNLaunchHelper {
}
return null;
- }
+ }
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static String[] getSupportedABIsLollipop() {
return Build.SUPPORTED_ABIS;
}
- private static String getMiniVPNExecutableName()
- {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
+ private static String getMiniVPNExecutableName() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
return MINIPIEVPN;
else
return MININONPIEVPN;
}
- public static String[] replacePieWithNoPie(String[] mArgv)
- {
+ public static String[] replacePieWithNoPie(String[] mArgv) {
mArgv[0] = mArgv[0].replace(MINIPIEVPN, MININONPIEVPN);
return mArgv;
}
@@ -79,7 +77,7 @@ public class VPNLaunchHelper {
String binaryName = writeMiniVPN(c);
// Add fixed paramenters
//args.add("/data/data/de.blinkt.openvpn/lib/openvpn");
- if(binaryName==null) {
+ if (binaryName == null) {
VpnStatus.logError("Error writing minivpn binary");
return null;
}
@@ -98,8 +96,7 @@ public class VPNLaunchHelper {
try {
mvpn = context.getAssets().open(getMiniVPNExecutableName() + "." + abi);
- }
- catch (IOException errabi) {
+ } catch (IOException errabi) {
VpnStatus.logInfo("Failed getting assets for archicture " + abi);
return false;
}
@@ -107,16 +104,16 @@ public class VPNLaunchHelper {
FileOutputStream fout = new FileOutputStream(mvpnout);
- byte buf[]= new byte[4096];
+ byte buf[] = new byte[4096];
int lenread = mvpn.read(buf);
- while(lenread> 0) {
+ while (lenread > 0) {
fout.write(buf, 0, lenread);
lenread = mvpn.read(buf);
}
fout.close();
- if(!mvpnout.setExecutable(true)) {
+ if (!mvpnout.setExecutable(true)) {
VpnStatus.logError("Failed to make OpenVPN executable");
return false;
}
@@ -129,14 +126,19 @@ public class VPNLaunchHelper {
}
}
-
- public static void startOpenVpn(VpnProfile startprofile, Context context) {
- Intent startVPN = startprofile.prepareStartService(context);
- if(startVPN!=null)
- context.startService(startVPN);
- }
+ public static void startOpenVpn(VpnProfile startprofile, Context context) {
+ Intent startVPN = startprofile.prepareStartService(context);
+ if (startVPN != null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ context.startForegroundService(startVPN);
+ else
+ context.startService(startVPN);
+
+ }
+ }
+
public static String getConfigFilePath(Context context) {
return context.getCacheDir().getAbsolutePath() + "/" + OVPNCONFIGFILE;