Search in sources :

Example 16 with PackageInfoData

use of dev.ukanth.ufirewall.Api.PackageInfoData in project afwall by ukanth.

the class LogInfo method parseLog.

public static String parseLog(Context ctx, List<LogData> listLogData) {
    // final BufferedReader r = new BufferedReader(new StringReader(dmesg.toString()));
    StringBuilder res = new StringBuilder();
    Integer appid;
    final SparseArray<LogInfo> map = new SparseArray<LogInfo>();
    LogInfo loginfo = null;
    try {
        for (LogData logData : listLogData) {
            appid = logData.getUid();
            loginfo = map.get(appid);
            if (loginfo == null) {
                loginfo = new LogInfo();
            }
            loginfo.dst = logData.getDst();
            loginfo.dpt = logData.getDpt();
            loginfo.spt = logData.getSpt();
            loginfo.proto = logData.getProto();
            loginfo.len = logData.getLen();
            loginfo.src = logData.getSrc();
            loginfo.out = logData.getOut();
            map.put(appid, loginfo);
            loginfo.totalBlocked += 1;
            String unique = "[" + loginfo.proto + "]" + loginfo.dst + ":" + loginfo.dpt;
            if (loginfo.dstBlocked.containsKey(unique)) {
                loginfo.dstBlocked.put(unique, loginfo.dstBlocked.get(unique) + 1);
            } else {
                loginfo.dstBlocked.put(unique, 1);
            }
        }
        final List<PackageInfoData> apps = Api.getApps(ctx, null);
        Integer id;
        String appName = "";
        int appId = -1;
        int totalBlocked;
        for (int i = 0; i < map.size(); i++) {
            StringBuilder address = new StringBuilder();
            id = map.keyAt(i);
            if (id != -1) {
                for (PackageInfoData app : apps) {
                    if (app.uid == id) {
                        appId = id;
                        appName = app.names.get(0);
                        break;
                    }
                }
            } else {
                appName = ctx.getString(R.string.unknown_item);
            }
            loginfo = map.valueAt(i);
            totalBlocked = loginfo.totalBlocked;
            if (loginfo.dstBlocked.size() > 0) {
                for (String unique : loginfo.dstBlocked.keySet()) {
                    address.append(unique).append("(").append(loginfo.dstBlocked.get(unique)).append(")");
                    address.append("\n");
                }
            }
            res.append("AppID :\t");
            res.append(appId);
            res.append("\n");
            res.append(ctx.getString(R.string.LogAppName));
            res.append(":\t");
            res.append(appName);
            res.append("\n");
            res.append(ctx.getString(R.string.LogPackBlock));
            res.append(":\t");
            res.append(totalBlocked);
            res.append("\n");
            res.append(address.toString());
            res.append("\n\t---------\n");
        }
    } catch (Exception e) {
        return null;
    }
    if (res.length() == 0) {
        res.append(ctx.getString(R.string.no_log));
    }
    return res.toString();
}
Also used : SparseArray(android.util.SparseArray) PackageInfoData(dev.ukanth.ufirewall.Api.PackageInfoData)

Aggregations

PackageInfoData (dev.ukanth.ufirewall.Api.PackageInfoData)16 BaseAdapter (android.widget.BaseAdapter)11 ListAdapter (android.widget.ListAdapter)11 AppListArrayAdapter (dev.ukanth.ufirewall.util.AppListArrayAdapter)3 PackageComparator (dev.ukanth.ufirewall.util.PackageComparator)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 ArrayAdapter (android.widget.ArrayAdapter)2 ArrayList (java.util.ArrayList)2 SparseArray (android.util.SparseArray)1 HashMap (java.util.HashMap)1