Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
x-falcon committed Jan 3, 2019
1 parent e3f6af7 commit 405bc95
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.github.xfalcon.vhosts"
minSdkVersion 19
targetSdkVersion 28
versionCode 33
versionName "2.0.4"
versionCode 34
versionName "2.0.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/com/github/xfalcon/vhosts/VhostsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,15 @@ private void selectFile() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
try {
Field f = android.provider.DocumentsContract.class.getField("EXTRA_SHOW_ADVANCED");
intent.putExtra(f.get(f.getName()).toString(), true);
String SHOW_ADVANCED;
try {
Field f = android.provider.DocumentsContract.class.getField("EXTRA_SHOW_ADVANCED");
SHOW_ADVANCED = f.get(f.getName()).toString();
}catch (NoSuchFieldException e){
LogUtils.e(TAG,e.getMessage(),e);
SHOW_ADVANCED = "android.content.extra.SHOW_ADVANCED";
}
intent.putExtra(SHOW_ADVANCED, true);
} catch (Throwable e) {
LogUtils.e(TAG, "SET EXTRA_SHOW_ADVANCED", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.net.VpnService;
import android.os.Build;
Expand Down Expand Up @@ -81,13 +82,17 @@ public void onCreate() {
super.onCreate();
if (isOAndBoot) {
//android 8.0 boot
NotificationChannel channel = new NotificationChannel("vhosts_channel_id", "System", NotificationManager.IMPORTANCE_MAX);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.createNotificationChannel(channel);
Notification notification = new Notification.Builder(this, "vhosts_channel_id")
.setSmallIcon(R.mipmap.ic_launcher) // the status icon
.build();
startForeground(1, notification);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("vhosts_channel_id", "System", NotificationManager.IMPORTANCE_NONE);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.createNotificationChannel(channel);
Notification notification = new Notification.Builder(this, "vhosts_channel_id")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Virtual Hosts Running")
.build();
startForeground(1, notification);
}
isOAndBoot=false;
}
setupHostFile();
setupVPN();
Expand Down Expand Up @@ -158,14 +163,16 @@ private void setupVPN() {
// builder.addRoute(VPN_ROUTE6,0);
builder.addDnsServer(VPN_DNS4);
builder.addDnsServer(VPN_DNS6);
try {
builder.addDisallowedApplication("com.android.vending"); //white list play store
builder.addDisallowedApplication("com.google.android.apps.docs"); //white list google drive
builder.addDisallowedApplication("com.google.android.apps.photos"); //white list google photos
builder.addDisallowedApplication("com.google.android.gm"); //white list gmail
builder.addDisallowedApplication("com.google.android.apps.translate"); //white list translate
} catch (Throwable e) {
LogUtils.d(TAG, "sdk < 21", e);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
String[] whiteList = {"com.android.vending", "com.google.android.apps.docs", "com.google.android.apps.photos", "com.google.android.gm", "com.google.android.apps.translate"};
for (String white : whiteList) {
try {
builder.addDisallowedApplication(white);
} catch (PackageManager.NameNotFoundException e) {
LogUtils.e(TAG, e.getMessage(), e);
}

}
}
vpnInterface = builder.setSession(getString(R.string.app_name)).setConfigureIntent(pendingIntent).establish();
}
Expand Down

0 comments on commit 405bc95

Please sign in to comment.