package com.scottyab.rootbeer.sample;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;
import com.scottyab.rootbeer.RootBeer;
import com.scottyab.rootbeer.util.Utils;
import java.util.ArrayList;
import uk.co.barbuzz.beerprogressview.BeerProgressView;
/* loaded from: classes.dex */
public class CheckRootTask extends AsyncTask<Boolean, Integer, Boolean> {
    private static final int SLEEP_TIME = 70;
    private static final String TAG = "CheckRootTask";
    private Drawable greenTick;
    private final BeerProgressView mBeerProgressView;
    private ArrayList<ImageView> mCheckRootimageViewList;
    private final Context mContext;
    private boolean mIsCheck;
    private OnCheckRootFinishedListener mListener;
    private Drawable redCross;

    /* loaded from: classes.dex */
    public interface OnCheckRootFinishedListener {
        void onCheckRootFinished(boolean z);
    }

    public CheckRootTask(Context ctx, OnCheckRootFinishedListener listener, BeerProgressView beerProgressView, ArrayList<ImageView> checkRootimageViewList) {
        this.mListener = listener;
        this.mBeerProgressView = beerProgressView;
        this.mContext = ctx;
        this.mCheckRootimageViewList = checkRootimageViewList;
    }

    @Override // android.os.AsyncTask
    protected void onPreExecute() {
        super.onPreExecute();
        this.redCross = this.mContext.getResources().getDrawable(R.drawable.ic_cross_red_24dp);
        this.greenTick = this.mContext.getResources().getDrawable(R.drawable.ic_tick_green_24dp);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.os.AsyncTask
    public void onProgressUpdate(Integer... values) {
        super.onProgressUpdate((Object[]) values);
        Integer value = values[0];
        this.mBeerProgressView.setBeerProgress(value.intValue());
        int index = (value.intValue() / 8) - 1;
        boolean isCheck = value.intValue() % 8 == 0;
        if ((index >= 0) & isCheck & (index < this.mCheckRootimageViewList.size())) {
            this.mCheckRootimageViewList.get(index).setImageDrawable(this.mIsCheck ? this.redCross : this.greenTick);
        }
        this.mIsCheck = false;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.os.AsyncTask
    public Boolean doInBackground(Boolean... params) {
        RootBeer check = new RootBeer(this.mContext);
        check.setLogging(true);
        for (int i = 0; i < 90; i++) {
            try {
                Thread.sleep(70L);
            } catch (InterruptedException e) {
            }
            switch (i) {
                case 8:
                    this.mIsCheck = check.detectRootManagementApps();
                    Log.d(TAG, "Root Management Apps " + (this.mIsCheck ? "detected" : "not detected"));
                    break;
                case 16:
                    this.mIsCheck = check.detectPotentiallyDangerousApps();
                    Log.d(TAG, "PotentiallyDangerousApps " + (this.mIsCheck ? "detected" : "not detected"));
                    break;
                case 24:
                    this.mIsCheck = check.detectTestKeys();
                    Log.d(TAG, "TestKeys " + (this.mIsCheck ? "detected" : "not detected"));
                    break;
                case 32:
                    this.mIsCheck = check.checkForBusyBoxBinary();
                    Log.d(TAG, "BusyBoxBinary " + (this.mIsCheck ? "detected" : "not detected"));
                    break;
                case 40:
                    this.mIsCheck = check.checkForSuBinary();
                    Log.d(TAG, "SU Binary " + (this.mIsCheck ? "detected" : "not detected"));
                    break;
                case 48:
                    this.mIsCheck = check.checkSuExists();
                    Log.d(TAG, "2nd SU Binary check " + (this.mIsCheck ? "detected" : "not detected"));
                    break;
                case 56:
                    this.mIsCheck = check.checkForRWPaths();
                    Log.d(TAG, "ForRWPaths " + (this.mIsCheck ? "detected" : "not detected"));
                    break;
                case 64:
                    this.mIsCheck = check.checkForDangerousProps();
                    Log.d(TAG, "DangerousProps " + (this.mIsCheck ? "detected" : "not detected"));
                    break;
                case 72:
                    this.mIsCheck = check.checkForRootNative();
                    Log.d(TAG, "Root via native check " + (this.mIsCheck ? "detected" : "not detected"));
                    break;
                case 80:
                    this.mIsCheck = check.detectRootCloakingApps();
                    Log.d(TAG, "RootCloakingApps " + (this.mIsCheck ? "detected" : "not detected"));
                    break;
                case 88:
                    this.mIsCheck = Utils.isSelinuxFlagInEnabled();
                    Log.d(TAG, "Selinux Flag Is Enabled " + (this.mIsCheck ? "true" : "false"));
                    break;
            }
            publishProgress(Integer.valueOf(i));
        }
        return Boolean.valueOf(check.isRooted());
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.os.AsyncTask
    public void onPostExecute(Boolean isRooted) {
        super.onPostExecute((CheckRootTask) isRooted);
        this.mListener.onCheckRootFinished(isRooted.booleanValue());
    }
}
