package com.ifpdos.debugmenu.action;

import android.content.Context;
import android.content.DialogInterface;
import android.os.RemoteException;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.cvte.tv.api.aidl.ITVApiSystemBoardSnAidl;
import com.cvte.tv.api.aidl.ITVApiSystemInformationAidl;
import com.cvte.tv.api.aidl.ITvApiManager;
import com.ifpdos.debugmenu.R;
import com.ifpdos.debugmenu.action.base.ItemButtonAction;
import com.ifpdos.debugmenu.event.ActivityEvent;
import com.seewo.sdk.model.SDKProjectInfo;
import d.f.a.i2.c;
import d.f.a.j2.e.e;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class ProjectIDSwitchAction extends ItemButtonAction {
    private static final String CONFIG_FILE_972 = "/mnt/vendor/odm_ext/etc/tvconfig/model/model_sum.ini";
    private static final String TAG = "ProjectIDSwitchAction";
    private Context mContext;
    private ITVApiSystemBoardSnAidl mITVApiSystemBoardSn;
    private ITVApiSystemInformationAidl mITVApiSystemInformationAidl;
    private List<SDKProjectInfo> mProjectInfoList;

    public ProjectIDSwitchAction(Context context) {
        super(context);
        this.mContext = context;
        int i2 = c.a;
        ITvApiManager iTvApiManager = c.b.a.f2587b;
        try {
            this.mITVApiSystemBoardSn = iTvApiManager.getTVApiSystemBoardSn();
            this.mITVApiSystemInformationAidl = iTvApiManager.getTVApiSystemInformation();
        } catch (RemoteException e2) {
            e2.printStackTrace();
        }
    }

    private View createSelectableView(Context context) {
        ArrayList arrayList = new ArrayList();
        Iterator<SDKProjectInfo> it = this.mProjectInfoList.iterator();
        while (it.hasNext()) {
            arrayList.add(it.next().getProjectName());
        }
        View viewInflate = ((LayoutInflater) context.getSystemService("layout_inflater")).inflate(R.layout.dialog_list_view_project, (ViewGroup) null);
        ListView listView = (ListView) viewInflate.findViewById(R.id.selection_list_view);
        TextView textView = (TextView) viewInflate.findViewById(R.id.dialog_title);
        textView.setText(R.string.str_project_id_list);
        textView.setVisibility(0);
        listView.setSelector(R.drawable.button_state);
        listView.setAdapter((ListAdapter) new ArrayAdapter(context, R.layout.dialog_list_project_item, arrayList));
        listView.setChoiceMode(1);
        return viewInflate;
    }

    private int getProjectIDIndexFor972() throws Throwable {
        String unifyValue = getUnifyValue("model_name");
        List<SDKProjectInfo> configFor972 = readConfigFor972();
        for (int i2 = 0; i2 < configFor972.size(); i2++) {
            if (configFor972.get(i2).getProjectName().equals(unifyValue)) {
                return i2;
            }
        }
        return -1;
    }

    /* JADX WARN: Removed duplicated region for block: B:40:0x0093 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private static java.util.List<com.seewo.sdk.model.SDKProjectInfo> readConfigFor972() throws java.lang.Throwable {
        /*
            java.lang.String r0 = "ProjectIDSwitchAction"
            java.util.ArrayList r1 = new java.util.ArrayList
            r1.<init>()
            java.lang.String r2 = "/mnt/vendor/odm_ext/etc/tvconfig/model/model_sum.ini"
            boolean r3 = d.b.a.a.a.a0(r2)
            if (r3 != 0) goto L10
            return r1
        L10:
            r3 = 0
            java.io.FileInputStream r4 = new java.io.FileInputStream     // Catch: java.lang.Throwable -> L7a java.lang.Exception -> L7c
            r4.<init>(r2)     // Catch: java.lang.Throwable -> L7a java.lang.Exception -> L7c
            java.io.BufferedReader r2 = new java.io.BufferedReader     // Catch: java.lang.Throwable -> L7a java.lang.Exception -> L7c
            java.io.InputStreamReader r5 = new java.io.InputStreamReader     // Catch: java.lang.Throwable -> L7a java.lang.Exception -> L7c
            r5.<init>(r4)     // Catch: java.lang.Throwable -> L7a java.lang.Exception -> L7c
            r2.<init>(r5)     // Catch: java.lang.Throwable -> L7a java.lang.Exception -> L7c
        L20:
            java.lang.String r3 = r2.readLine()     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            if (r3 == 0) goto L72
            java.lang.String r3 = r3.trim()     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            java.lang.String r4 = "["
            boolean r4 = r3.startsWith(r4)     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            if (r4 == 0) goto L20
            java.lang.String r4 = "]"
            boolean r4 = r3.endsWith(r4)     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            if (r4 == 0) goto L20
            int r4 = r3.length()     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            r5 = 1
            int r4 = r4 - r5
            java.lang.String r3 = r3.substring(r5, r4)     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            java.lang.String r4 = "UHD_1RG"
            boolean r4 = r4.equals(r3)     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            if (r4 == 0) goto L4d
            goto L20
        L4d:
            com.seewo.sdk.model.SDKProjectInfo r4 = new com.seewo.sdk.model.SDKProjectInfo     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            int r5 = r1.size()     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            r4.<init>(r3, r5)     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            r1.add(r4)     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            java.lang.StringBuilder r3 = new java.lang.StringBuilder     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            r3.<init>()     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            java.lang.String r5 = "readConfigFor972: "
            r3.append(r5)     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            java.lang.String r4 = r4.getProjectName()     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            r3.append(r4)     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            java.lang.String r3 = r3.toString()     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            android.util.Log.i(r0, r3)     // Catch: java.lang.Exception -> L78 java.lang.Throwable -> L8d
            goto L20
        L72:
            int r0 = k.a.a.b.a.a
            r2.close()     // Catch: java.io.IOException -> L8c
            goto L8c
        L78:
            r3 = move-exception
            goto L80
        L7a:
            r0 = move-exception
            goto L8f
        L7c:
            r2 = move-exception
            r6 = r3
            r3 = r2
            r2 = r6
        L80:
            java.lang.String r4 = ""
            android.util.Log.e(r0, r4, r3)     // Catch: java.lang.Throwable -> L8d
            int r0 = k.a.a.b.a.a
            if (r2 == 0) goto L8c
            r2.close()     // Catch: java.io.IOException -> L8c
        L8c:
            return r1
        L8d:
            r0 = move-exception
            r3 = r2
        L8f:
            int r1 = k.a.a.b.a.a
            if (r3 == 0) goto L96
            r3.close()     // Catch: java.io.IOException -> L96
        L96:
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ifpdos.debugmenu.action.ProjectIDSwitchAction.readConfigFor972():java.util.List");
    }

    private void setProjectIDIndexFor972(int i2) throws Throwable {
        List<SDKProjectInfo> configFor972 = readConfigFor972();
        if (i2 >= 0 && i2 < configFor972.size()) {
            SDKProjectInfo sDKProjectInfo = configFor972.get(i2);
            setUnifyValue("model_name", sDKProjectInfo.getProjectName());
            try {
                this.mITVApiSystemInformationAidl.eventSystemEnvironmentSet("ubootenv.var.model_name", sDKProjectInfo.getProjectName());
            } catch (RemoteException e2) {
                e2.printStackTrace();
            }
        }
        Log.d(TAG, "setProjectIDIndexFor972: " + i2);
    }

    public String getUnifyValue(String str) {
        try {
            String strEventSystemUnifykeyGet = this.mITVApiSystemBoardSn.eventSystemUnifykeyGet(str);
            return strEventSystemUnifykeyGet == null ? "" : strEventSystemUnifykeyGet;
        } catch (RemoteException unused) {
            return "";
        }
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemButtonAction
    public String getValue(Context context) {
        setColor(-7829368);
        return getUnifyValue("model_name");
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemButtonAction, d.f.a.j2.e.e.a
    public void onClick(Context context, e eVar) {
        this.mProjectInfoList = readConfigFor972();
        k.c.a.c.c().g(new ActivityEvent.ShowNormalDialog(createSelectableView(this.mContext), new DialogInterface.OnCancelListener() { // from class: com.ifpdos.debugmenu.action.ProjectIDSwitchAction.1
            @Override // android.content.DialogInterface.OnCancelListener
            public void onCancel(DialogInterface dialogInterface) {
            }
        }));
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemButtonAction, d.f.a.j2.e.e.a
    public void onLongClick(Context context, e eVar) {
    }

    public void setUnifyValue(String str, String str2) {
        try {
            this.mITVApiSystemBoardSn.eventSystemUnifykeySet(str, str2);
        } catch (RemoteException unused) {
        }
    }
}
