mirror of https://github.com/M66B/NetGuard.git
parent
47deeba343
commit
4938053953
|
@ -713,6 +713,49 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
prefs.edit().putBoolean("nodoze", cbDontAsk.isChecked()).apply();
|
||||
}
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialogInterface) {
|
||||
dialogDoze = null;
|
||||
checkDataSaving();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
dialogDoze.show();
|
||||
} else
|
||||
checkDataSaving();
|
||||
} else
|
||||
checkDataSaving();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDataSaving() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
final Intent settings = new Intent(
|
||||
Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS,
|
||||
Uri.parse("package:" + getPackageName()));
|
||||
if (Util.dataSaving(this) && getPackageManager().resolveActivity(settings, 0) != null) {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if (!prefs.getBoolean("nodata", false)) {
|
||||
LayoutInflater inflater = LayoutInflater.from(this);
|
||||
View view = inflater.inflate(R.layout.datasaving, null, false);
|
||||
final CheckBox cbDontAsk = (CheckBox) view.findViewById(R.id.cbDontAsk);
|
||||
dialogDoze = new AlertDialog.Builder(this)
|
||||
.setView(view)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
prefs.edit().putBoolean("nodata", cbDontAsk.isChecked()).apply();
|
||||
startActivity(settings);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
prefs.edit().putBoolean("nodata", cbDontAsk.isChecked()).apply();
|
||||
}
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialogInterface) {
|
||||
|
@ -724,8 +767,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
}
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -607,7 +607,9 @@ public class Util {
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
||||
sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode()));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
sb.append(String.format("Battery optimizing %B\r\n", !pm.isIgnoringBatteryOptimizations(context.getPackageName())));
|
||||
sb.append(String.format("Battery optimizing %B\r\n", batteryOptimizing(context)));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
sb.append(String.format("Data saving %B\r\n", dataSaving(context)));
|
||||
|
||||
if (sb.length() > 2)
|
||||
sb.setLength(sb.length() - 2);
|
||||
|
@ -675,6 +677,12 @@ public class Util {
|
|||
return !pm.isIgnoringBatteryOptimizations(context.getPackageName());
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.N)
|
||||
public static boolean dataSaving(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
return (cm.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
|
||||
public static String getSubscriptionInfo(Context context) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:src="@mipmap/ic_launcher" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="@string/app_name"
|
||||
android:textAppearance="@style/TextLarge"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/msg_datasaving"
|
||||
android:textAppearance="@style/TextMedium" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbDontAsk"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/title_dontask"
|
||||
android:textAppearance="@style/TextMedium" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
|
@ -167,6 +167,8 @@ Your internet traffic is not being sent to a remote VPN server.</string>
|
|||
<string name="msg_count">%dx</string>
|
||||
<string name="msg_doze">For consistent results, the Android battery optimizations should be disabled for NetGuard.
|
||||
\n\nIn the next dialog, select \"All apps\" at the top, tap on NetGuard in the list and select and confirm \"Don\'t optimize\".</string>
|
||||
<string name="msg_datasaving">For consistent results, the Android data saving options should be disabled for NetGuard
|
||||
\n\nIn the next dialog, enable the options \"Background data\" and \"Unrestricted data usage\"</string>
|
||||
<string name="msg_filter">Using filtering will cause Android to attribute data and power usage to NetGuard - Android assumes the data and power are being used by NetGuard, rather than the original applications</string>
|
||||
<string name="msg_log_disabled">Traffic logging is disabled, use the switch above to enable logging. Traffic logging might result in extra battery usage.</string>
|
||||
<string name="msg_clear_rules">This will reset the rules and conditions to their default values</string>
|
||||
|
|
Loading…
Reference in New Issue