mirror of https://github.com/M66B/NetGuard.git
Merge remote-tracking branch 'refs/remotes/M66B/master'
This commit is contained in:
commit
32d7175cdc
|
@ -1,7 +1,9 @@
|
|||
package eu.faircode.netguard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.preference.PreferenceManager;
|
||||
|
@ -11,6 +13,7 @@ import android.util.Log;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Filter;
|
||||
|
@ -44,6 +47,7 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
|
|||
public ImageView ivUsing;
|
||||
public LinearLayout llConfiguration;
|
||||
public CheckBox cbUsing;
|
||||
public Button btnLaunch;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
@ -59,6 +63,7 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
|
|||
ivUsing = (ImageView) itemView.findViewById(R.id.ivUsing);
|
||||
llConfiguration = (LinearLayout) itemView.findViewById(R.id.llConfiguration);
|
||||
cbUsing = (CheckBox) itemView.findViewById(R.id.cbUsing);
|
||||
btnLaunch = (Button) itemView.findViewById(R.id.btnLaunch);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,6 +174,16 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
|
|||
SinkholeService.reload(null, context);
|
||||
}
|
||||
});
|
||||
|
||||
PackageManager pm = context.getPackageManager();
|
||||
final Intent launch = pm.getLaunchIntentForPackage(rule.info.packageName);
|
||||
holder.btnLaunch.setEnabled(launch != null);
|
||||
holder.btnLaunch.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
context.startActivity(launch);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -182,7 +197,8 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
|
|||
else {
|
||||
query = query.toString().toLowerCase();
|
||||
for (Rule rule : listAll)
|
||||
if (rule.name.toLowerCase().contains(query))
|
||||
if (rule.info.packageName.toLowerCase().contains(query) ||
|
||||
(rule.name != null && rule.name.toLowerCase().contains(query)))
|
||||
listResult.add(rule);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ public class SinkholeService extends VpnService {
|
|||
private boolean debug = false;
|
||||
private Thread thread = null;
|
||||
|
||||
private static final int NOTIFY_DISABLED = 1;
|
||||
private static final String EXTRA_COMMAND = "Command";
|
||||
|
||||
private enum Command {start, reload, stop}
|
||||
|
@ -49,6 +50,8 @@ public class SinkholeService extends VpnService {
|
|||
if (enabled && vpn == null) {
|
||||
vpn = startVPN();
|
||||
startDebug(vpn);
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.cancel(NOTIFY_DISABLED);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -271,20 +274,6 @@ public class SinkholeService extends VpnService {
|
|||
unregisterReceiver(connectivityChangedReceiver);
|
||||
unregisterReceiver(interactiveStateReceiver);
|
||||
|
||||
// Display notification
|
||||
Intent riMain = new Intent(this, ActivityMain.class);
|
||||
PendingIntent piMain = PendingIntent.getActivity(this, 0, riMain, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
|
||||
NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText(getString(R.string.msg_revoked))
|
||||
.setContentIntent(piMain)
|
||||
.setAutoCancel(true);
|
||||
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.notify(0, notification.build());
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@ -302,6 +291,20 @@ public class SinkholeService extends VpnService {
|
|||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
prefs.edit().putBoolean("enabled", false).apply();
|
||||
|
||||
// Display notification
|
||||
Intent riMain = new Intent(this, ActivityMain.class);
|
||||
PendingIntent piMain = PendingIntent.getActivity(this, 0, riMain, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
|
||||
NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText(getString(R.string.msg_revoked))
|
||||
.setContentIntent(piMain)
|
||||
.setAutoCancel(true);
|
||||
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.notify(NOTIFY_DISABLED, notification.build());
|
||||
|
||||
super.onRevoke();
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,16 @@ public class Util {
|
|||
return pm.isInteractive();
|
||||
}
|
||||
|
||||
public static boolean isPackageInstalled(String packageName, Context context) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
try {
|
||||
PackageInfo info = pm.getPackageInfo(packageName, 0);
|
||||
} catch (PackageManager.NameNotFoundException ignored) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void toast(final String text, final int length, final Context context) {
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
|
@ -84,6 +94,7 @@ public class Util {
|
|||
sb.insert(0, "\r\n");
|
||||
sb.insert(0, "Please decribe your problem:\r\n");
|
||||
sb.insert(0, "\r\n");
|
||||
sb.insert(0, String.format("VPN dialogs: %b\r\n", isPackageInstalled("com.android.vpndialogs", context)));
|
||||
sb.insert(0, String.format("Id: %s\r\n", Build.ID));
|
||||
sb.insert(0, String.format("Display: %s\r\n", Build.DISPLAY));
|
||||
sb.insert(0, String.format("Host: %s\r\n", Build.HOST));
|
||||
|
|
|
@ -104,5 +104,11 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_using"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Small" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnLaunch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_launch" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
|
@ -16,4 +16,5 @@
|
|||
<string name="msg_revoked">NetGuard has been disabled</string>
|
||||
|
||||
<string name="title_using">السماح عند استخدام الجهاز</string>
|
||||
<string name="title_launch">Start application</string>
|
||||
</resources>
|
||||
|
|
|
@ -16,4 +16,5 @@
|
|||
<string name="msg_revoked">NetGuard has been disabled</string>
|
||||
|
||||
<string name="title_using">Allow when device in use</string>
|
||||
<string name="title_launch">Start application</string>
|
||||
</resources>
|
||||
|
|
|
@ -16,4 +16,5 @@
|
|||
<string name="msg_revoked">NetGuard has been disabled</string>
|
||||
|
||||
<string name="title_using">Consenti quando il dispositivo è in uso</string>
|
||||
<string name="title_launch">Start application</string>
|
||||
</resources>
|
||||
|
|
|
@ -16,4 +16,5 @@
|
|||
<string name="msg_revoked">NetGuard is uitgezet</string>
|
||||
|
||||
<string name="title_using">Sta toe als apparaat in gebruik</string>
|
||||
<string name="title_launch">Start applicatie</string>
|
||||
</resources>
|
||||
|
|
|
@ -16,4 +16,5 @@
|
|||
<string name="msg_revoked">NetGuard has been disabled</string>
|
||||
|
||||
<string name="title_using">Permite cand dispozitivul este folosit</string>
|
||||
<string name="title_launch">Start application</string>
|
||||
</resources>
|
||||
|
|
|
@ -16,4 +16,5 @@
|
|||
<string name="msg_revoked">NetGuard je vypnutý</string>
|
||||
|
||||
<string name="title_using">Povoliť pri používaní zariadenia</string>
|
||||
<string name="title_launch">Start application</string>
|
||||
</resources>
|
||||
|
|
|
@ -16,5 +16,6 @@
|
|||
<string name="msg_revoked">NetGuard has been disabled</string>
|
||||
|
||||
<string name="title_using">Allow when device in use</string>
|
||||
<string name="title_launch">Start application</string>
|
||||
</resources>
|
||||
|
||||
|
|
|
@ -17,4 +17,5 @@
|
|||
<string name="msg_revoked">NetGuard has been disabled</string>
|
||||
|
||||
<string name="title_using">Allow when device in use</string>
|
||||
<string name="title_launch">Start application</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue