Added option to reset network usage statistics

This commit is contained in:
M66B 2016-02-15 19:49:33 +01:00
parent 66aee047a9
commit 4df3eb535f
5 changed files with 63 additions and 5 deletions

View File

@ -172,13 +172,30 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
cat_advanced.removePreference(screen.findPreference("filter_allowed"));
}
// Show resolved
Preference pref_show_resolved = screen.findPreference("show_resolved");
pref_show_resolved.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
Preference pref_reset_usage = screen.findPreference("reset_usage");
pref_reset_usage.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivity(new Intent(ActivitySettings.this, ActivityDns.class));
return true;
new AsyncTask<Object, Object, Throwable>() {
@Override
protected Throwable doInBackground(Object... objects) {
try {
DatabaseHelper.getInstance(ActivitySettings.this).resetUsage(-1);
return null;
} catch (Throwable ex) {
return ex;
}
}
@Override
protected void onPostExecute(Throwable ex) {
if (ex == null)
Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show();
else
Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
}
}.execute();
return false;
}
});
@ -324,6 +341,16 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
prefs.edit().remove("loglevel").apply();
}
// Show resolved
Preference pref_show_resolved = screen.findPreference("show_resolved");
pref_show_resolved.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivity(new Intent(ActivitySettings.this, ActivityDns.class));
return true;
}
});
// Handle technical info
Preference.OnPreferenceClickListener listener = new Preference.OnPreferenceClickListener() {
@Override

View File

@ -592,6 +592,30 @@ public class DatabaseHelper extends SQLiteOpenHelper {
notifyAccessChanged();
}
public void resetUsage(int uid) {
mLock.writeLock().lock();
try {
SQLiteDatabase db = this.getWritableDatabase();
db.beginTransactionNonExclusive();
try {
ContentValues cv = new ContentValues();
cv.putNull("sent");
cv.putNull("received");
db.update("access", cv,
(uid < 0 ? null : "uid = ?"),
(uid < 0 ? null : new String[]{Integer.toString(uid)}));
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
} finally {
mLock.writeLock().unlock();
}
notifyAccessChanged();
}
public Cursor getAccess(int uid) {
mLock.readLock().lock();
try {

View File

@ -75,6 +75,7 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
<string name="setting_filter_allowed">Filter allowed traffic</string>
<string name="setting_resolved">Store resolved domain names</string>
<string name="setting_track_usage">Track network usage</string>
<string name="setting_reset_usage">Reset network usage</string>
<string name="setting_show_resolved" translatable="false">Show resolved domain names</string>
<string name="setting_block_domains">Block domain names</string>
<string name="setting_forwarding">Port forwarding</string>

View File

@ -124,6 +124,9 @@
android:key="track_usage"
android:summary="@string/summary_track_usage"
android:title="@string/setting_track_usage" />
<Preference
android:key="reset_usage"
android:title="@string/setting_reset_usage" />
<CheckBoxPreference
android:defaultValue="true"
android:dependency="filter_allowed"

View File

@ -124,6 +124,9 @@
android:key="track_usage"
android:summary="@string/summary_track_usage"
android:title="@string/setting_track_usage" />
<Preference
android:key="reset_usage"
android:title="@string/setting_reset_usage" />
<eu.faircode.netguard.SwitchPreference
android:defaultValue="true"
android:dependency="filter_allowed"