package com.ifpdos.debugmenu.action;

import android.content.Context;
import android.util.Log;
import com.ifpdos.debugmenu.action.base.ItemInfoAction;
import d.b.a.a.a;
import d.f.a.v0;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/* JADX INFO: loaded from: classes.dex */
public class ShowKernelVersionAction extends ItemInfoAction implements v0 {
    private static final String FILENAME_PROC_VERSION = "/proc/version";
    private static final String TAG = "ShowKernelVersionAction";
    private static final String UNAVAILABLE = "Unavailable";
    private Context mContext;
    private String standard_data;

    public ShowKernelVersionAction(Context context) {
        super(context);
        this.mContext = context;
    }

    private static String formatKernelVersion(String str) {
        Matcher matcher = Pattern.compile("Linux version (\\S+) \\((\\S+?)\\) (?:\\(gcc.+? \\)) (#\\d+) (?:.*?)?((Sun|Mon|Tue|Wed|Thu|Fri|Sat).+)").matcher(str);
        if (!matcher.matches()) {
            Log.e(TAG, "Regex did not match on /proc/version: " + str);
            return UNAVAILABLE;
        }
        if (matcher.groupCount() < 4) {
            StringBuilder sbB = a.B("Regex match on /proc/version only returned ");
            sbB.append(matcher.groupCount());
            sbB.append(" groups");
            Log.e(TAG, sbB.toString());
            return UNAVAILABLE;
        }
        return matcher.group(1) + "\nrel@iip " + matcher.group(3) + "\n" + matcher.group(4);
    }

    public static String formatKernelVersionEarlier(String str) {
        Matcher matcher = Pattern.compile("Linux version (\\S+) \\((\\S+)\\).*(#\\d+).*((?:Sun|Mon|Tue|Wed|Thu|Fri|Sat).+)").matcher(str);
        if (!matcher.matches()) {
            Log.e(TAG, "Regex did not match on /proc/version: " + str);
            return UNAVAILABLE;
        }
        if (matcher.groupCount() < 4) {
            StringBuilder sbB = a.B("Regex match on /proc/version only returned ");
            sbB.append(matcher.groupCount());
            sbB.append(" groups");
            Log.e(TAG, sbB.toString());
            return UNAVAILABLE;
        }
        return matcher.group(1) + "\n" + matcher.group(2) + " " + matcher.group(3) + "\n" + matcher.group(4);
    }

    private String getFormattedKernelVersion() {
        try {
            String line = readLine(FILENAME_PROC_VERSION);
            String kernelVersion = formatKernelVersion(line);
            return UNAVAILABLE.equals(kernelVersion) ? formatKernelVersionEarlier(line).replace("\n", "\t") : kernelVersion;
        } catch (Exception e2) {
            Log.e(TAG, "getFormattedKernelVersion: ", e2);
            return UNAVAILABLE;
        }
    }

    private static String readLine(String str) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(str), 256);
        try {
            String line = bufferedReader.readLine();
            bufferedReader.close();
            return line;
        } catch (Throwable th) {
            try {
                bufferedReader.close();
            } catch (Throwable th2) {
                th.addSuppressed(th2);
            }
            throw th;
        }
    }

    private String removeDirtyString(String str) {
        return !str.contains("dirty") ? str : str.replaceAll("-?dirty", "").replaceAll("--", "-");
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemInfoAction
    public String getValue(Context context) {
        String strRemoveDirtyString = removeDirtyString(getFormattedKernelVersion());
        Log.i(TAG, strRemoveDirtyString);
        return strRemoveDirtyString;
    }

    @Override // d.f.a.v0
    public void setStandData(String str) {
        this.standard_data = str;
    }
}
