Skip to content

Commit

Permalink
Fix whitelist flag shown with firewall disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuele-f committed Dec 12, 2022
1 parent ac7a6e4 commit bbafcbe
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.emanuelef.remote_capture.adapters;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -29,6 +30,7 @@

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.RecyclerView;

import com.emanuelef.remote_capture.Billing;
Expand All @@ -40,6 +42,7 @@
import com.emanuelef.remote_capture.AppsResolver;
import com.emanuelef.remote_capture.model.Blocklist;
import com.emanuelef.remote_capture.model.MatchList;
import com.emanuelef.remote_capture.model.Prefs;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -48,6 +51,7 @@
public class AppsStatsAdapter extends RecyclerView.Adapter<AppsStatsAdapter.ViewHolder> {
private static final String TAG = "AppsStatsAdapter";
private final Context mContext;
private final SharedPreferences mPrefs;
private final LayoutInflater mLayoutInflater;
private final Drawable mUnknownIcon;
private final Blocklist mBlocklist;
Expand Down Expand Up @@ -96,10 +100,11 @@ public void bindAppStats(AppStats stats) {
boolean isGracedApp = mBlocklist.isExemptedApp(stats.getUid());
boolean isBlockedApp = mBlocklist.matchesApp(stats.getUid());
boolean isWhitelistedApp = mWhitelist.matchesApp(stats.getUid());
boolean isWhitelistEnabled = Prefs.isFirewallEnabled(mContext, mPrefs) && Prefs.isFirewallWhitelistMode(mPrefs);

traffic.setText(Utils.formatBytes(stats.sentBytes + stats.rcvdBytes));
blockedFlag.setVisibility(isBlockedApp ? View.VISIBLE : View.GONE);
whitelistedFlag.setVisibility(isWhitelistedApp ? View.VISIBLE : View.GONE);
whitelistedFlag.setVisibility(isWhitelistEnabled && isWhitelistedApp ? View.VISIBLE : View.GONE);
tempUnblocked.setVisibility(isGracedApp ? View.VISIBLE : View.GONE);
}
}
Expand All @@ -109,6 +114,7 @@ public AppsStatsAdapter(Context context) {
mApps = new AppsResolver(context);
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mUnknownIcon = ContextCompat.getDrawable(mContext, android.R.drawable.ic_menu_help);
mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
mBlocklist = PCAPdroid.getInstance().getBlocklist();
mWhitelist = PCAPdroid.getInstance().getFirewallWhitelist();
mListener = null;
Expand Down

0 comments on commit bbafcbe

Please sign in to comment.