package com.ss.android.ugc.aweme.fe.method;

import X.0CB;
import X.0CH;
import X.6Is;
import X.7ZI;
import X.C3127JMg;
import X.C3128JMh;
import X.C3129JMi;
import X.C3131JMk;
import X.FIu;
import X.JXH;
import X.KKi;
import android.app.Activity;
import android.content.Context;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.fe.base.BaseCommonJavaMethod;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

public final class RequestPermissionMethod extends BaseCommonJavaMethod implements 6Is {
    public static final C3129JMi LIZ = new C3129JMi((byte) 0);

    static {
        Covode.recordClassIndex(76149);
    }

    public RequestPermissionMethod(byte b) {
        this();
    }

    public final void onStateChanged(0CH r1, 0CB r2) {
        RequestPermissionMethod.super.onStateChanged(r1, r2);
    }

    public /* synthetic */ RequestPermissionMethod() {
        this((KKi) null);
    }

    public RequestPermissionMethod(KKi kKi) {
        super(kKi);
    }

    private final void LIZ(int i, List<String> list) {
        String[] strArr = (String[]) 7ZI.LIZ.get(Integer.valueOf(i));
        if (strArr != null) {
            for (String add : strArr) {
                list.add(add);
            }
        }
    }

    public final void handle(JSONObject jSONObject, FIu fIu) {
        JSONArray optJSONArray;
        if (jSONObject != null && fIu != null) {
            Context actContext = getActContext();
            if (!(actContext instanceof Activity)) {
                actContext = null;
            }
            Activity activity = (Activity) actContext;
            if (activity != null && (optJSONArray = jSONObject.optJSONArray("permission_list")) != null) {
                ArrayList arrayList = new ArrayList();
                int length = optJSONArray.length();
                for (int i = 0; i < length; i++) {
                    Object obj = optJSONArray.get(i);
                    if (obj instanceof Integer) {
                        LIZ(((Number) obj).intValue(), arrayList);
                    }
                }
                int size = arrayList.size();
                String[] strArr = new String[size];
                for (int i2 = 0; i2 < size; i2++) {
                    strArr[i2] = "";
                }
                String[] strArr2 = (String[]) arrayList.toArray(strArr);
                if (strArr2 != null) {
                    C3127JMg jMg = new C3127JMg(activity, fIu);
                    List<String> LIZ2 = C3131JMk.LIZ(activity, strArr2);
                    if (LIZ2 == null || LIZ2.isEmpty()) {
                        jMg.LIZ();
                    } else {
                        JXH.LIZ(activity, strArr2, new C3128JMh(jMg));
                    }
                }
            }
        }
    }
}
