package ZtlApi;

import ZtlApi.CpuInfo;
import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.database.ContentObserver;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Environment;
import android.os.PowerManager;
import android.os.StatFs;
import android.os.SystemClock;
import android.os.storage.StorageManager;
import android.provider.Settings;
import android.support.v4.media.session.PlaybackStateCompat;
import android.support.v4.os.EnvironmentCompat;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import androidx.core.app.ActivityCompat;
import com.google.android.exoplayer2.util.MimeTypes;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;

public class ZtlManager {
    static ZtlManager Instance = null;
    static String TAG = "ZtlManager";
    String ALARM_OFF;
    String ALARM_ON;
    String BlFile;
    String BlOff;
    String BlOn;
    String CAMERA_ORIENTATION_PROP;
    boolean DEBUG_ZTL;
    String HdmiEnableFile;
    String IS_OPEN_ALARM;
    String LCD_DENSITY_PROP;
    String POWER_ON_TIME;
    String TP_ORIENTATION_PROP;
    CpuInfo cpuInfo;
    protected Context mContext;

    private static native int setScreenResolution(String str);

    public String getJARVersion() {
        return "2.7";
    }

    public int getSystemMaxBrightness() {
        return 255;
    }

    public void setGPUMode(String str) {
    }

    public void setResolution(String str) {
    }

    public static ZtlManager GetInstance() {
        if (Instance == null) {
            String deviceVersion = getDeviceVersion();
            if (deviceVersion.contains("3288") && getAndroidVersion().contains("5.1")) {
                Instance = new ZtlManager();
            } else if (deviceVersion.contains("3399")) {
                Instance = new ZtlManager33997_1();
            } else if (deviceVersion.contains("3288") && getAndroidVersion().contains("7.1")) {
                Instance = new ZtlManager32887_1();
            } else if (deviceVersion.contains("3328")) {
                Instance = new ZtlManager33287_1();
            } else if (deviceVersion.contains("3368")) {
                Instance = new ZtlManager3368();
            } else if (deviceVersion.contains("3126") || deviceVersion.contains("3128")) {
                Instance = new ZtlManager3128();
            } else if (deviceVersion.contains("A64") || deviceVersion.contains("A33")) {
                Instance = new ZtlManagerA33_A64();
            }
            if (Instance == null) {
                Instance = new ZtlManager();
            }
        }
        return Instance;
    }

    public void setContext(Context context) {
        this.mContext = context;
    }

    ZtlManager() {
        this.DEBUG_ZTL = false;
        this.BlFile = "/proc/bl_root/bl_entry";
        this.HdmiEnableFile = "/sys/class/display/HDMI/enable";
        this.BlOn = "1";
        this.BlOff = "0";
        this.POWER_ON_TIME = "persist.sys.powerontime";
        this.IS_OPEN_ALARM = "persist.sys.isopenalarm";
        this.ALARM_ON = "1";
        this.ALARM_OFF = "0";
        this.LCD_DENSITY_PROP = "persist.sys.ztl_density";
        this.CAMERA_ORIENTATION_PROP = "persist.sys.cameraOrientation";
        this.TP_ORIENTATION_PROP = "persist.sys.tp.orientation";
        this.DEBUG_ZTL = getSystemProperty("persist.sys.ztl.debug", "false").equals("true");
    }

    /* access modifiers changed from: package-private */
    public void LOGD(String str) {
        if (this.DEBUG_ZTL) {
            Log.d(TAG, str);
        }
    }

    public static String getDeviceVersion() {
        return Build.MODEL;
    }

    public static String getAndroidVersion() {
        return Build.VERSION.RELEASE;
    }

    public int getSDKVersion() {
        return Build.VERSION.SDK_INT;
    }

    public String getDeviceID() {
        File file = new File("/proc/cpuinfo");
        if (!file.exists()) {
            LOGD("/proc/cpuinfo not found!");
            return null;
        }
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine == null) {
                    break;
                } else if (readLine.contains("Serial")) {
                    LOGD(readLine.length() + readLine);
                    String substring = readLine.substring(readLine.indexOf(":") + 2);
                    LOGD(substring);
                    return substring;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public long getTotalInternalMemorySize() {
        StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
        long blockCount = ((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize());
        long j = ((blockCount / PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID) / PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID) / PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID;
        return blockCount;
    }

    public long getFreeMemorySize() {
        ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
        ((ActivityManager) this.mContext.getSystemService("activity")).getMemoryInfo(memoryInfo);
        return memoryInfo.availMem;
    }

    public String getInternalSDCardPath() {
        return System.getenv("EXTERNAL_STORAGE");
    }

    public String getExternalSDCardPath() {
        return getAppRootOfSdCardRemovable();
    }

    private String getAppRootOfSdCardRemovable() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return null;
        } else if (!Environment.getExternalStorageState().equals("mounted")) {
            return null;
        } else {
            StorageManager storageManager = (StorageManager) this.mContext.getSystemService("storage");
            try {
                Class<?> cls = Class.forName("android.os.storage.StorageVolume");
                Method method = storageManager.getClass().getMethod("getVolumeList", new Class[0]);
                Method method2 = cls.getMethod("getPath", new Class[0]);
                Method method3 = cls.getMethod("isRemovable", new Class[0]);
                Object invoke = method.invoke(storageManager, new Object[0]);
                int length = Array.getLength(invoke);
                for (int i = 0; i < length; i++) {
                    Object obj = Array.get(invoke, i);
                    String str = (String) method2.invoke(obj, new Object[0]);
                    if (((Boolean) method3.invoke(obj, new Object[0])).booleanValue()) {
                        return str;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    }

    public String getUsbStoragePath() {
        File file = new File("/mnt/usb_storage/");
        Log.e("File", "" + file);
        String str = null;
        try {
            if (!file.exists() || !file.isDirectory()) {
                return null;
            }
            File[] listFiles = file.listFiles();
            if (listFiles.length <= 0) {
                return null;
            }
            str = listFiles[0].getAbsolutePath();
            Log.e("steve : get file path ", "" + str);
            if (!str.contains("USB_DISK")) {
                return str;
            }
            Log.e("steve : open ", "" + str);
            File file2 = new File(str);
            if (!file2.exists() || !file2.isDirectory()) {
                return str;
            }
            File[] listFiles2 = file2.listFiles();
            if (listFiles2.length == 1) {
                String absolutePath = listFiles2[0].getAbsolutePath();
                Log.e("steve : usbPath ", "" + absolutePath);
                return absolutePath;
            }
            for (int i = 0; i < listFiles2.length; i++) {
                if (!listFiles2[i].getAbsolutePath().contains("(")) {
                    String absolutePath2 = listFiles2[i].getAbsolutePath();
                    Log.e("steve : usbPath ", "" + absolutePath2);
                    return absolutePath2;
                }
            }
            return str;
        } catch (Exception e) {
            e.printStackTrace();
            return str;
        }
    }

    public void sleep() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "sleep");
        this.mContext.startService(intent);
    }

    public void awake() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "awake");
        this.mContext.startService(intent);
    }

    public void shutdown() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "shutdown");
        this.mContext.startService(intent);
    }

    public void reboot(int i) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "reboot");
        intent.putExtra("delay", i);
        this.mContext.startService(intent);
    }

    public void startScreenShot(String str, String str2) {
        if (isExist(str)) {
            execRootCmdSilent("screencap -p " + (str + "/" + str2));
            return;
        }
        Log.e(TAG, "file path " + str + " not exist");
    }

    public void setLauncher(String str, String str2) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "setLauncher");
        intent.putExtra("package", str);
        intent.putExtra("activity", str2);
        this.mContext.startService(intent);
    }

    public boolean isAppExist(String str) {
        ApplicationInfo applicationInfo;
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return false;
        }
        try {
            applicationInfo = context.getPackageManager().getApplicationInfo(str, 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            applicationInfo = null;
        }
        if (applicationInfo != null) {
            return true;
        }
        return false;
    }

    public void resetSystem() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "resetSystem");
        this.mContext.startService(intent);
    }

    public int startSettings() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return -1;
        }
        try {
            context.startActivity(new Intent("android.settings.SETTINGS"));
            return 0;
        } catch (Exception unused) {
            LOGD("start settings fail!");
            return -1;
        }
    }

    public int startWifiSettings() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return -1;
        }
        try {
            context.startActivity(new Intent("android.settings.WIFI_SETTINGS"));
            return 0;
        } catch (Exception unused) {
            LOGD("start wifi settings fail!");
            return -1;
        }
    }

    public void openSystemBar(boolean z) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        String str = z ? "0" : "1";
        Intent intent = new Intent("com.ding.systembar.chang");
        intent.putExtra("enable", str);
        this.mContext.sendBroadcast(intent);
    }

    public boolean isSystemBarOpen() {
        return Integer.parseInt(getSystemProperty("persist.sys.barState", "1")) != 0;
    }

    public void openUsbDebug(boolean z) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        String str = z ? "1" : "0";
        Intent intent = new Intent("com.ding.adbsetting");
        intent.putExtra("enable", str);
        this.mContext.sendBroadcast(intent);
    }

    public boolean isUsbDebugOpen() {
        return Integer.valueOf(getSystemProperty("persist.sys.adbState", "1")).intValue() == 1;
    }

    public boolean getUSBtoPC() {
        try {
            if (loadFileAsString("/sys/bus/platform/drivers/usb20_otg/force_usb_mode").contains("2")) {
                return true;
            }
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }

    public void setUSBtoPC(boolean z) {
        String str = z ? "2" : "1";
        setSystemProperty("persist.usb.mode", str);
        writeMethod("/sys/bus/platform/drivers/usb20_otg/force_usb_mode", str);
    }

    public int setBuildSerial(String str) {
        if (str == null) {
            return 0;
        }
        setSystemProperty("persist.sys.ztlsn", str);
        return 0;
    }

    public String getBuildSerial() {
        return getSystemProperty("persist.sys.ztlsn", EnvironmentCompat.MEDIA_UNKNOWN);
    }

    public int execRootCmdSilent(String str) {
        try {
            return _execCmdAsSU("su", str);
        } catch (Exception e) {
            String exc = e.toString();
            if (exc.contains("Directory: null Environment: null") || exc.contains("Permission")) {
                Log.e(TAG, "无SU执行权限,正在尝试testsu");
                try {
                    return _execCmdAsSU("testsu", str);
                } catch (Exception unused) {
                    e.printStackTrace();
                    Log.e(TAG, "此函数连接失败，请联系厂家解决");
                    return -1;
                }
            } else {
                Log.e(TAG, "testsu的权限不通过");
                e.printStackTrace();
                Log.e(TAG, "无SU执行权限,请联系厂家解决");
                return -1;
            }
        }
    }

    /* access modifiers changed from: package-private */
    public int _execCmdAsSU(String str, String str2) throws Exception {
        Process exec = Runtime.getRuntime().exec(str);
        DataOutputStream dataOutputStream = new DataOutputStream(exec.getOutputStream());
        dataOutputStream.writeBytes(str2 + "\n");
        dataOutputStream.flush();
        dataOutputStream.writeBytes("exit\n");
        dataOutputStream.flush();
        int waitFor = exec.waitFor();
        dataOutputStream.close();
        return waitFor;
    }

    public void setBootPackageActivity(String str, String str2) {
        if (str == null || str2 == null) {
            setSystemProperty("persist.sys.bootPkgName", EnvironmentCompat.MEDIA_UNKNOWN);
            setSystemProperty("persist.sys.bootPkgActivity", EnvironmentCompat.MEDIA_UNKNOWN);
            return;
        }
        setSystemProperty("persist.sys.bootPkgName", str);
        setSystemProperty("persist.sys.bootPkgActivity", str2);
    }

    public String getBootPackageName() {
        return getSystemProperty("persist.sys.bootPkgName", EnvironmentCompat.MEDIA_UNKNOWN);
    }

    public String getBootPackageActivity() {
        return getSystemProperty("persist.sys.bootPkgActivity", EnvironmentCompat.MEDIA_UNKNOWN);
    }

    public void startActivity(String str, String str2) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
        } else if (str == null || str2 == null) {
            Log.e(TAG, "pkg is null please check it");
        } else {
            try {
                ComponentName componentName = new ComponentName(str, str2);
                Intent intent = new Intent();
                intent.setComponent(componentName);
                this.mContext.startActivity(intent);
            } catch (Exception unused) {
                LOGD("start app (" + str + "," + str2 + ") fail!");
            }
        }
    }

    public void installAppSilent(String str) {
        if (!isExist(str)) {
            String str2 = TAG;
            Log.e(str2, "file [" + str + "] not isExist");
        } else if (!str.contains(".apk")) {
            String str3 = TAG;
            Log.e(str3, "file [" + str + "] 后缀不合法");
        } else {
            execRootCmdSilent("pm install -r " + str);
        }
    }

    public void installApp(String str, String str2) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "install");
        intent.putExtra("filepath", str);
        intent.putExtra("package", str2);
        this.mContext.startService(intent);
    }

    public void uninstallAppSilent(String str) {
        try {
            execRootCmdSilent("pm uninstall " + str);
        } catch (Exception unused) {
            String str2 = TAG;
            Log.e(str2, "uninstall package " + str + " faild");
        }
    }

    public void installAppSilentAndRebootSystem(String str, int i) {
        reboot(i);
        installAppSilent(str);
    }

    public void installAppAndStartUp(String str, String str2) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "start_up_app");
        intent.putExtra("package", str2);
        this.mContext.startService(intent);
        Intent intent2 = new Intent();
        intent2.setComponent(new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService"));
        intent2.putExtra("cmd", "install");
        intent2.putExtra("filepath", str);
        intent2.putExtra("package", str2);
        this.mContext.startService(intent2);
    }

    public void keepActivity(String str) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.appservice", "com.ztl.appservice.BasicService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "keepActivity");
        intent.putExtra("package", str);
        this.mContext.startService(intent);
    }

    public void unKeepActivity() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.appservice", "com.ztl.appservice.BasicService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "unkeepActivity");
        this.mContext.startService(intent);
    }

    public void keepService(String str, String str2) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.appservice", "com.ztl.appservice.BasicService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "keepService");
        intent.putExtra("package", str);
        intent.putExtra("service", str2);
        this.mContext.startService(intent);
    }

    public void unkeepService() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.appservice", "com.ztl.appservice.BasicService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "unkeepService");
        this.mContext.startService(intent);
    }

    public String getSystemDate() {
        Calendar instance = Calendar.getInstance();
        int i = instance.get(1);
        int i2 = instance.get(5);
        return i + "/" + (instance.get(2) + 1) + "/" + i2;
    }

    public String getSystemTime() {
        Calendar instance = Calendar.getInstance();
        int i = instance.get(11);
        int i2 = instance.get(12);
        int i3 = instance.get(13);
        return i + ":" + i2 + ":" + i3;
    }

    public void syncNetworkTime() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "sync_time_now");
        this.mContext.startService(intent);
    }

    public void setSyncNetworkTimePeroid(int i) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "sync_time_period");
        intent.putExtra("peroid", i);
        this.mContext.startService(intent);
    }

    public void setSystemTime(Calendar calendar) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "setSystemTime");
        intent.putExtra("time", calendar.getTimeInMillis());
        this.mContext.startService(intent);
    }

    public boolean isAutoTimezone() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return false;
        }
        try {
            if (Settings.Global.getInt(context.getContentResolver(), "auto_time_zone") > 0) {
                return true;
            }
            return false;
        } catch (Settings.SettingNotFoundException e) {
            e.printStackTrace();
            return false;
        }
    }

    public void setAutoTimezone(boolean z) {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
        } else {
            Settings.Global.putInt(context.getContentResolver(), "auto_time_zone", z ? 1 : 0);
        }
    }

    public boolean isAutoDateTime() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return false;
        }
        try {
            if (Settings.Global.getInt(context.getContentResolver(), "auto_time") > 0) {
                return true;
            }
            return false;
        } catch (Settings.SettingNotFoundException e) {
            e.printStackTrace();
            return false;
        }
    }

    public void setAutoDateTime(boolean z) {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
        } else {
            Settings.Global.putInt(context.getContentResolver(), "auto_time", z ? 1 : 0);
        }
    }

    public void setSchedulePowerOn(int i, int i2, boolean z) {
        long currentTimeMillis = System.currentTimeMillis() / 1000;
        Calendar instance = Calendar.getInstance();
        instance.set(instance.get(1), instance.get(2), instance.get(5), i, i2, 0);
        if (!z) {
            instance.setTimeInMillis(0);
        }
        _setPowerOn(instance.getTimeInMillis() / 1000, true);
    }

    public void setSchedulePowerOff(int i, int i2, boolean z) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
        } else if (!z) {
            setSystemProperty("persist.sys.powerOffTime", EnvironmentCompat.MEDIA_UNKNOWN);
            setSystemProperty("persist.sys.powerOffEnable", "false");
        } else {
            Calendar instance = Calendar.getInstance();
            long timeInMillis = instance.getTimeInMillis();
            instance.set(11, i);
            instance.set(12, i2);
            instance.set(13, 0);
            long timeInMillis2 = instance.getTimeInMillis();
            if (timeInMillis2 < timeInMillis) {
                instance.add(5, 1);
                timeInMillis2 = instance.getTimeInMillis();
            }
            ((AlarmManager) this.mContext.getSystemService("alarm")).set(0, instance.getTimeInMillis(), PendingIntent.getBroadcast(this.mContext, 0, new Intent("com.android.settings.action.REQUEST_POWER_OFF"), 268435456));
            setSystemProperty("persist.sys.powerOffTime", i + ":" + i2);
            setSystemProperty("persist.sys.powerOffEnable", "true");
            setSystemProperty("persist.sys.powerOffEveryday", "true");
            setSystemProperty("persist.sys.powerOffTimeMillis", (timeInMillis2 / 1000) + "");
            String str = TAG;
            Log.i(str, "Next time power off " + i + ":" + i2);
        }
    }

    public void setPowerOnAlarm(int i, int i2, int i3, int i4, int i5, boolean z) {
        Calendar instance = Calendar.getInstance();
        instance.set(i, i2 - 1, i3, i4, i5, 0);
        if (!z) {
            instance.setTimeInMillis(0);
        }
        _setPowerOn(instance.getTimeInMillis() / 1000, false);
    }

    public void setPowerOffAlarm(int i, int i2, int i3, int i4, int i5, boolean z) {
        int i6 = i4;
        int i7 = i5;
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        Calendar instance = Calendar.getInstance();
        long timeInMillis = instance.getTimeInMillis() / 1000;
        if (!z) {
            setSystemProperty("persist.sys.powerOffTime", EnvironmentCompat.MEDIA_UNKNOWN);
            setSystemProperty("persist.sys.powerOffEnable", "false");
            return;
        }
        int i8 = i2 - 1;
        int i9 = i8;
        String str = "persist.sys.powerOffEnable";
        String str2 = "false";
        instance.set(i, i8, i3, i4, i5, 0);
        long timeInMillis2 = instance.getTimeInMillis() / 1000;
        Log.d(TAG, "set false tar " + timeInMillis2 + " cur" + timeInMillis);
        if (timeInMillis2 < timeInMillis) {
            Log.d(TAG, "set false tar " + timeInMillis2 + " cur" + timeInMillis);
            setSystemProperty(str, str2);
            return;
        }
        Log.d(TAG, "set next time power off " + i + "/" + i9 + "/" + i3 + " " + i6 + ":" + i7);
        ((AlarmManager) this.mContext.getSystemService("alarm")).set(0, instance.getTimeInMillis(), PendingIntent.getBroadcast(this.mContext, 0, new Intent("com.android.settings.action.REQUEST_POWER_OFF"), 268435456));
        StringBuilder sb = new StringBuilder();
        sb.append(i6);
        sb.append(":");
        sb.append(i7);
        setSystemProperty("persist.sys.powerOffTime", sb.toString());
        setSystemProperty(str, "true");
        setSystemProperty("persist.sys.powerOffEveryday", str2);
        setSystemProperty("persist.sys.powerOffTimeMillis", timeInMillis2 + "");
    }

    /* access modifiers changed from: package-private */
    public void _setPowerOn(long j, boolean z) {
        if (j == 0) {
            setSystemProperty(this.POWER_ON_TIME, "0");
            setSystemProperty(this.IS_OPEN_ALARM, this.ALARM_OFF);
            return;
        }
        String str = this.POWER_ON_TIME;
        setSystemProperty(str, j + "");
        setSystemProperty(this.IS_OPEN_ALARM, this.ALARM_ON);
        if (!z) {
            setSystemProperty("persist.sys.iseverydayalarm", "0");
        } else {
            setSystemProperty("persist.sys.iseverydayalarm", "1");
        }
    }

    public long getStringToDate(String str, String str2) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(str2);
        Date date = new Date();
        try {
            date = simpleDateFormat.parse(str);
            Log.d("steve", " " + date.getYear() + " " + date.getMonth() + " " + date.getDay() + " " + date.getHours() + " " + date.getMinutes() + " " + date.getSeconds());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date.getTime();
    }

    public String getDisplayMode() {
        return getSystemProperty("persist.sys.screenmode", "0");
    }

    public int getDisplayHeight() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return -1;
        }
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getRealMetrics(displayMetrics);
        return displayMetrics.heightPixels;
    }

    public int getDisplayWidth() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return -1;
        }
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getRealMetrics(displayMetrics);
        return displayMetrics.widthPixels;
    }

    public int getDisplayDensity() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return -1;
        }
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getRealMetrics(displayMetrics);
        return displayMetrics.densityDpi;
    }

    public void setDisplayDensity(int i) {
        String str = TAG;
        Log.d(str, "set lcd density value = " + i);
        String str2 = "160";
        getSystemProperty("ro.sf.lcd_density", str2);
        int parseInt = Integer.parseInt(getSystemProperty(this.LCD_DENSITY_PROP, "0"));
        if (i == 0) {
            str2 = "120";
        } else if (i != 1) {
            if (i == 2) {
                str2 = "240";
            } else if (i != 3) {
                i = Math.abs(i);
                str2 = String.valueOf(i);
            } else {
                str2 = "320";
            }
        }
        execRootCmdSilent("wm density " + i);
        setSystemProperty(this.LCD_DENSITY_PROP, str2);
        execRootCmdSilent("reboot");
    }

    public void reverseBrighness(boolean z) {
        if (z) {
            setSystemProperty("persist.ztl.reverseBri", "1");
        } else {
            setSystemProperty("persist.ztl.reverseBri", "0");
        }
    }

    public boolean isReverseBrighness() {
        return getSystemProperty("persist.ztl.reverseBri", "1").equals("1");
    }

    public int setLcdBackLight(int i) {
        if (!isExist(this.BlFile)) {
            Log.e(TAG, "lcd bl node not found");
        } else if (i == 1) {
            writeMethod(this.BlFile, this.BlOn);
        } else if (i == 0) {
            writeMethod(this.BlFile, this.BlOff);
        } else {
            Log.e(TAG, "status illegal");
        }
        if (!isExist(this.HdmiEnableFile)) {
            Log.e(TAG, "hdmi enable node not found");
        } else if (i == 1) {
            writeMethod(this.HdmiEnableFile, this.BlOn);
            return 0;
        } else if (i == 0) {
            writeMethod(this.HdmiEnableFile, this.BlOff);
            return 0;
        } else {
            Log.e(TAG, "status illegal");
        }
        return -1;
    }

    public int getSystemBrightness() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return -1;
        }
        try {
            return Settings.System.getInt(context.getContentResolver(), "screen_brightness");
        } catch (Settings.SettingNotFoundException e) {
            e.printStackTrace();
            return 0;
        }
    }

    public void increaseBrightness() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "increaseBrightness");
        this.mContext.startService(intent);
    }

    public void decreaseBrightness() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "decreaseBrightness");
        this.mContext.startService(intent);
    }

    public void setBrightness(int i) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "setBrightness");
        intent.putExtra("brightness", i);
        this.mContext.startService(intent);
    }

    public void setDisplayOrientation(int i) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
        } else if (i == getDisplayOrientation()) {
            Log.e("当前方向", "与旋转方向一致，不执行");
        } else {
            int i2 = i / 90;
            try {
                Intent intent = new Intent("ACTION_ZTL_ROTATION");
                intent.putExtra("rotation", i2);
                this.mContext.sendBroadcast(intent);
            } catch (Exception unused) {
                Log.e(TAG, "set rotation err!");
            }
        }
    }

    public int getDisplayOrientation() {
        return Integer.parseInt(getSystemProperty("persist.ztl.hwrotation", "0"));
    }

    public void setTouchOrientation(int i, boolean z) {
        try {
            setSystemProperty(this.TP_ORIENTATION_PROP, Integer.toString(i / 90));
            if (z) {
                execRootCmdSilent("reboot");
            }
        } catch (Exception unused) {
        }
    }

    public int getTouchOrientation() {
        return Integer.valueOf(getSystemProperty(this.TP_ORIENTATION_PROP, "0")).intValue() * 90;
    }

    public void setSplitScreenLeftRightEnable(boolean z) {
        if (z) {
            setSystemProperty("persist.sys.leftRightEnable", "true");
        } else {
            setSystemProperty("persist.sys.leftRightEnable", "false");
        }
    }

    public void setSplitScreenUpDownEnable(boolean z) {
        if (z) {
            setSystemProperty("persist.sys.upDownEnable", "true");
        } else {
            setSystemProperty("persist.sys.upDownEnable", "false");
        }
    }

    public String[] getScreenModes() {
        Log.e("ztllib", "unsupport fucntion now for this board.todo later.");
        return null;
    }

    public void setScreenMode(String str) {
        boolean equals = getSystemProperty("persist.sys.leftRightEnable", "false").equals("true");
        boolean equals2 = getSystemProperty("persist.sys.upDownEnable", "false").equals("true");
        if (str != null) {
            int i = 15;
            if (!str.equals("800x600@60p")) {
                if (!str.equals("1024x768@60p")) {
                    if (str.equals("1280x1024@60p")) {
                        i = 3;
                    } else {
                        if (!str.equals("1280x720@60p")) {
                            if (!str.equals("1366x768@60p")) {
                                if (!str.equals("1440x900@60p")) {
                                    if (!str.equals("1600x900@60p")) {
                                        if (!str.equals("1920x1080@60p")) {
                                            if (str.equals("1600x600@60p")) {
                                                if (equals) {
                                                    i = 6;
                                                }
                                            } else if (str.equals("2048x768@60p")) {
                                                if (equals) {
                                                    i = 7;
                                                }
                                            } else if (str.equals("2560x720@60p")) {
                                                if (equals) {
                                                    i = 8;
                                                }
                                            } else if (str.equals("2732x768@60p")) {
                                                if (equals) {
                                                    i = 17;
                                                }
                                            } else if (str.equals("2880x900@60p")) {
                                                if (equals) {
                                                    i = 18;
                                                }
                                            } else if (str.equals("3200x900@60p")) {
                                                if (equals) {
                                                    i = 19;
                                                }
                                            } else if (str.equals("3840x1080@60p")) {
                                                if (equals) {
                                                    i = 9;
                                                }
                                            } else if (str.equals("1600x1800@60p")) {
                                                if (equals2) {
                                                    i = 11;
                                                }
                                            } else if (str.equals("1280x1440@60p")) {
                                                if (equals2) {
                                                    i = 12;
                                                }
                                            } else if (!str.equals("1920x2160@60p")) {
                                                LOGD("set screen mode dwError , please check mode list");
                                                return;
                                            } else if (equals2) {
                                                i = 13;
                                            }
                                        }
                                        i = 5;
                                    }
                                    i = 16;
                                }
                            }
                            i = 14;
                        }
                        i = 4;
                    }
                    String str2 = "lcdparamservice " + i;
                    LOGD("set screen mode " + str2);
                    execRootCmdSilent(str2);
                    return;
                }
                i = 2;
                String str22 = "lcdparamservice " + i;
                LOGD("set screen mode " + str22);
                execRootCmdSilent(str22);
                return;
            }
            i = 1;
            String str222 = "lcdparamservice " + i;
            LOGD("set screen mode " + str222);
            execRootCmdSilent(str222);
            return;
        }
        LOGD("mode is null , please check it");
    }

    public void setFontSize(int i) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        LOGD("set font size value = " + i);
        Intent intent = new Intent("com.action.ztl.fontsize");
        intent.putExtra("fontsize", i);
        this.mContext.sendBroadcast(intent);
    }

    /* access modifiers changed from: package-private */
    public NetworkInfo getConnectedType() {
        NetworkInfo activeNetworkInfo;
        Context context = this.mContext;
        if (context == null || (activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo()) == null || !activeNetworkInfo.isAvailable()) {
            return null;
        }
        return activeNetworkInfo;
    }

    public int getNetWorkType() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return -1;
        }
        NetworkInfo connectedType = getConnectedType();
        if (connectedType == null) {
            return -1;
        }
        if (connectedType.getType() == 9) {
            return 0;
        }
        if (connectedType.getType() == 1) {
            return 1;
        }
        if (connectedType.getType() == 0) {
            int subtype = connectedType.getSubtype();
            TelephonyManager telephonyManager = (TelephonyManager) this.mContext.getSystemService("phone");
            int i = 2;
            if (!(subtype == 1 || subtype == 2 || subtype == 4 || (subtype == 16 && !telephonyManager.isNetworkRoaming()))) {
                i = 3;
                if (!(subtype == 3 || subtype == 8 || (subtype == 5 && !telephonyManager.isNetworkRoaming()))) {
                    if (subtype == 13) {
                        return 4;
                    }
                    if (subtype == 20) {
                        return 5;
                    }
                }
            }
            return i;
        }
        return -1;
    }

    public String getMacAddress() {
        try {
            return loadFileAsString("/sys/class/net/eth0/address").toUpperCase().substring(0, 17);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public void keepWifiConnect(String str, String str2) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "keepWifiConnect");
        intent.putExtra("ssid", str);
        intent.putExtra("psw", str2);
        this.mContext.startService(intent);
    }

    public void stopKeepWifiConnect() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "stopKeepWifiConnect");
        this.mContext.startService(intent);
    }

    public void setNetAdb(boolean z) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "set_net_adb");
        intent.putExtra("enable", z);
        this.mContext.startService(intent);
    }

    public void openAp(String str, String str2) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "openAP");
        intent.putExtra("ssid", str);
        intent.putExtra("psw", str2);
        this.mContext.startService(intent);
    }

    public void closeAp() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "closeAP");
        this.mContext.startService(intent);
    }

    public String getLocalIpAddress() {
        try {
            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
            while (networkInterfaces.hasMoreElements()) {
                Enumeration<InetAddress> inetAddresses = networkInterfaces.nextElement().getInetAddresses();
                while (true) {
                    if (inetAddresses.hasMoreElements()) {
                        InetAddress nextElement = inetAddresses.nextElement();
                        if (!nextElement.isLoopbackAddress() && !nextElement.getHostAddress().toString().contains("::")) {
                            return nextElement.getHostAddress().toString();
                        }
                    }
                }
            }
            return null;
        } catch (SocketException unused) {
            return null;
        }
    }

    public String getIPv4(String str) {
        try {
            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
            while (networkInterfaces.hasMoreElements()) {
                NetworkInterface nextElement = networkInterfaces.nextElement();
                if (str.equals(nextElement.getDisplayName())) {
                    Enumeration<InetAddress> inetAddresses = nextElement.getInetAddresses();
                    while (inetAddresses.hasMoreElements()) {
                        InetAddress nextElement2 = inetAddresses.nextElement();
                        if (!nextElement2.isLoopbackAddress() && (nextElement2 instanceof Inet4Address)) {
                            return nextElement2.getHostAddress().toString();
                        }
                    }
                    continue;
                }
            }
            return null;
        } catch (Exception unused) {
            Log.e(TAG, "获取IP信息出错");
            return null;
        }
    }

    public void setEthIP(boolean z, String str, String str2, String str3, String str4, String str5) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "set_ethip");
        intent.putExtra("staitc", z);
        intent.putExtra("ip", str);
        intent.putExtra("mask", str2);
        intent.putExtra("gate", str3);
        intent.putExtra("dns", str4);
        intent.putExtra("dns2", str5);
        this.mContext.startService(intent);
    }

    public void setWifiIP(String str, String str2, boolean z, String str3, String str4, String str5, String str6, String str7) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "set_wifiip");
        intent.putExtra("ssid", str);
        intent.putExtra("psw", str2);
        intent.putExtra("staitc", z);
        intent.putExtra("ip", str3);
        intent.putExtra("mask", str4);
        intent.putExtra("gate", str5);
        intent.putExtra("dns", str6);
        intent.putExtra("dns2", str7);
        this.mContext.startService(intent);
    }

    public void enable4GReset(boolean z) {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "4greset");
        intent.putExtra("enable", z);
        this.mContext.startService(intent);
    }

    public String getSimImei() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return "";
        }
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
        if (ActivityCompat.checkSelfPermission(this.mContext, "android.permission.READ_PHONE_STATE") != 0) {
            return "";
        }
        return telephonyManager.getDeviceId();
    }

    public String getSimTel() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return "";
        }
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
        if (ActivityCompat.checkSelfPermission(this.mContext, "android.permission.READ_SMS") == 0 || ActivityCompat.checkSelfPermission(this.mContext, "android.permission.READ_PHONE_NUMBERS") == 0 || ActivityCompat.checkSelfPermission(this.mContext, "android.permission.READ_PHONE_STATE") == 0) {
            return telephonyManager.getLine1Number();
        }
        return "";
    }

    public String getSimIccid() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return "";
        }
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
        if (ActivityCompat.checkSelfPermission(this.mContext, "android.permission.READ_PHONE_STATE") != 0) {
            return "";
        }
        return telephonyManager.getSimSerialNumber();
    }

    public String getSimImsi() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return "";
        }
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
        if (ActivityCompat.checkSelfPermission(this.mContext, "android.permission.READ_PHONE_STATE") != 0) {
            return "";
        }
        return telephonyManager.getSubscriberId();
    }

    public String getSimOperator() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return "";
        }
        String simOperator = ((TelephonyManager) context.getSystemService("phone")).getSimOperator();
        if (simOperator == null) {
            return "";
        }
        if (simOperator.equals("46000") || simOperator.equals("46002") || simOperator.equals("46007")) {
            return "CMCC";
        }
        if (simOperator.equals("46001")) {
            return "CUCC";
        }
        if (simOperator.equals("46003")) {
            return "CT";
        }
        return "";
    }

    /* access modifiers changed from: package-private */
    /* JADX WARNING: Removed duplicated region for block: B:18:0x002b A[SYNTHETIC, Splitter:B:18:0x002b] */
    /* JADX WARNING: Removed duplicated region for block: B:23:0x0036 A[SYNTHETIC, Splitter:B:23:0x0036] */
    /* JADX WARNING: Removed duplicated region for block: B:31:? A[RETURN, SYNTHETIC] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void writeMethod(java.lang.String r6, java.lang.String r7) {
        /*
            r5 = this;
            r0 = 0
            java.io.BufferedWriter r1 = new java.io.BufferedWriter     // Catch:{ Exception -> 0x0025 }
            java.io.OutputStreamWriter r2 = new java.io.OutputStreamWriter     // Catch:{ Exception -> 0x0025 }
            java.io.FileOutputStream r3 = new java.io.FileOutputStream     // Catch:{ Exception -> 0x0025 }
            r4 = 1
            r3.<init>(r6, r4)     // Catch:{ Exception -> 0x0025 }
            r2.<init>(r3)     // Catch:{ Exception -> 0x0025 }
            r1.<init>(r2)     // Catch:{ Exception -> 0x0025 }
            r1.write(r7)     // Catch:{ Exception -> 0x0020, all -> 0x001d }
            r1.close()     // Catch:{ IOException -> 0x0018 }
            goto L_0x001c
        L_0x0018:
            r6 = move-exception
            r6.printStackTrace()
        L_0x001c:
            return
        L_0x001d:
            r6 = move-exception
            r0 = r1
            goto L_0x0034
        L_0x0020:
            r6 = move-exception
            r0 = r1
            goto L_0x0026
        L_0x0023:
            r6 = move-exception
            goto L_0x0034
        L_0x0025:
            r6 = move-exception
        L_0x0026:
            r6.printStackTrace()     // Catch:{ all -> 0x0023 }
            if (r0 == 0) goto L_0x0033
            r0.close()     // Catch:{ IOException -> 0x002f }
            goto L_0x0033
        L_0x002f:
            r6 = move-exception
            r6.printStackTrace()
        L_0x0033:
            return
        L_0x0034:
            if (r0 == 0) goto L_0x003e
            r0.close()     // Catch:{ IOException -> 0x003a }
            goto L_0x003e
        L_0x003a:
            r7 = move-exception
            r7.printStackTrace()
        L_0x003e:
            throw r6
        */
        throw new UnsupportedOperationException("Method not decompiled: ZtlApi.ZtlManager.writeMethod(java.lang.String, java.lang.String):void");
    }

    public String getFileType(String str) {
        if (!isExist(str)) {
            return "";
        }
        String name = new File(str).getName();
        return name.substring(name.lastIndexOf(".") + 1);
    }

    public boolean isExist(String str) {
        try {
            return new File(str).exists();
        } catch (Exception unused) {
            return false;
        }
    }

    /* access modifiers changed from: package-private */
    public String loadFileAsString(String str) throws IOException {
        StringBuffer stringBuffer = new StringBuffer(1000);
        BufferedReader bufferedReader = new BufferedReader(new FileReader(str));
        char[] cArr = new char[1024];
        while (true) {
            int read = bufferedReader.read(cArr);
            if (read != -1) {
                stringBuffer.append(String.valueOf(cArr, 0, read));
            } else {
                bufferedReader.close();
                return stringBuffer.toString();
            }
        }
    }

    public int gpioStringToInt(String str) {
        if (!str.contains("GPIO")) {
            Log.e(TAG, "传入参数错误,请传入GPIO7_A5之类的，实际以规格书为准");
            return -1;
        }
        return (((((str.charAt(4) - '0') & 255) * 32) + ((str.charAt(6) - 'A') * 8)) + str.charAt(7)) - 48;
    }

    public void setGpioValue(String str, int i) {
        if (!str.contains("GPIO")) {
            Log.e(TAG, "传入参数错误,请传入GPIO7_A5之类的，实际以规格书为准");
            return;
        }
        Gpio gpio = new Gpio();
        if (gpio.open(str)) {
            gpio.setValue("out", i);
        }
    }

    public int getGpioValue(String str, String str2) {
        if (!str.contains("GPIO")) {
            Log.e(TAG, "传入参数错误,请传入GPIO7_A5之类的，实际以规格书为准");
            return -1;
        }
        Gpio gpio = new Gpio();
        if (!gpio.open(str)) {
            return -1;
        }
        gpio.setDirection(str2);
        return gpio.getValue();
    }

    public void setGpioDirection(String str, String str2) {
        if (!str.contains("GPIO")) {
            Log.e(TAG, "传入参数错误,请传入GPIO7_A5之类的，实际以规格书为准");
            return;
        }
        Gpio gpio = new Gpio();
        if (gpio.open(str)) {
            gpio.setDirection(str2);
        }
    }

    public String getGpioDirection(String str) {
        if (!str.contains("GPIO")) {
            Log.e(TAG, "传入参数错误,请传入GPIO7_A5之类的，实际以规格书为准");
            return null;
        }
        Gpio gpio = new Gpio();
        gpioStringToInt(str);
        if (!gpio.open(str)) {
            return null;
        }
        return gpio.getDirection();
    }

    public int getSystemMaxVolume() {
        Context context = this.mContext;
        if (context != null) {
            return ((AudioManager) context.getSystemService(MimeTypes.BASE_TYPE_AUDIO)).getStreamMaxVolume(3);
        }
        Log.e("上下文为空", "不执行");
        return -1;
    }

    public int getSystemCurrenVolume() {
        Context context = this.mContext;
        if (context != null) {
            return ((AudioManager) context.getSystemService(MimeTypes.BASE_TYPE_AUDIO)).getStreamVolume(3);
        }
        Log.e("上下文为空", "不执行");
        return -1;
    }

    public int setRaiseSystemVolume() {
        int systemCurrenVolume = getSystemCurrenVolume() + 1;
        if (systemCurrenVolume > getSystemMaxVolume()) {
            systemCurrenVolume = getSystemMaxVolume();
        }
        return setSystemVolumeIndex(systemCurrenVolume);
    }

    public int setLowerSystemVolume() {
        int systemCurrenVolume = getSystemCurrenVolume() - 1;
        if (systemCurrenVolume < 0) {
            systemCurrenVolume = 0;
        }
        return setSystemVolumeIndex(systemCurrenVolume);
    }

    public int setSystemVolumeIndex(int i) {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return -1;
        }
        try {
            AudioManager audioManager = (AudioManager) context.getSystemService(MimeTypes.BASE_TYPE_AUDIO);
            int streamMaxVolume = audioManager.getStreamMaxVolume(3);
            if (i < 0 || i > streamMaxVolume) {
                return 0;
            }
            audioManager.setStreamVolume(3, i, 4);
            return 0;
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }

    public void setCameraOrientation(int i) {
        if (i < 0 || i > 3) {
            Log.e(TAG, "set camera orientation value(" + i + ") err!,set close");
            i = 4;
        }
        String str = i + "";
        Log.d(TAG, "set camera orientation value = " + i);
        try {
            setSystemProperty(this.CAMERA_ORIENTATION_PROP, str);
        } catch (Exception unused) {
            Log.w(TAG, "Unable to set camera orientation");
        }
    }

    public int getCameraOrientation() {
        return Integer.parseInt(getSystemProperty("persist.sys.cameraOrientation", "0"));
    }

    public boolean isCameraMirror() {
        return !getSystemProperty("persist.ztl.ismirror", "0").contains("0");
    }

    public void setCameraMirror(boolean z) {
        setSystemProperty("persist.ztl.ismirror", z ? "1" : "0");
    }

    public String getSystemProperty(String str, String str2) {
        try {
            Class<?> cls = Class.forName("android.os.SystemProperties");
            String str3 = (String) cls.getDeclaredMethod("get", new Class[]{String.class}).invoke(cls.newInstance(), new Object[]{str});
            if (!TextUtils.isEmpty(str3)) {
                return str3;
            }
            return str2;
        } catch (Exception unused) {
            Log.d(TAG, "Unable to read system properties");
        }
    }

    public void setSystemProperty(String str, String str2) {
        try {
            Class<?> cls = Class.forName("android.os.SystemProperties");
            cls.getMethod("set", new Class[]{String.class, String.class}).invoke(cls, new Object[]{str, str2});
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /* access modifiers changed from: package-private */
    public PendingIntent getPendingIntent(String str, int i) {
        Intent intent = new Intent();
        intent.setAction(str);
        return PendingIntent.getBroadcast(this.mContext, i, intent, 268435456);
    }

    public void openMonitor() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        ComponentName componentName = new ComponentName("com.ztl.helper", "com.ztl.helper.ZTLHelperService");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.putExtra("cmd", "open_monitor");
        this.mContext.startService(intent);
    }

    public String[] getCPUFreq() {
        if (this.cpuInfo == null) {
            CpuInfo cpuInfo2 = new CpuInfo();
            this.cpuInfo = cpuInfo2;
            cpuInfo2.Init((CpuInfo.Eventhandler) null);
        }
        return CpuInfo.SubCore.getFreq();
    }

    public void setCPUFreq(String str) {
        if (this.cpuInfo == null) {
            CpuInfo cpuInfo2 = new CpuInfo();
            this.cpuInfo = cpuInfo2;
            cpuInfo2.Init((CpuInfo.Eventhandler) null);
        }
        this.cpuInfo.setCPUFreq(str);
    }

    @Deprecated
    public void goToSleep() {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        PowerManager powerManager = (PowerManager) context.getSystemService("power");
        try {
            powerManager.getClass().getMethod("goToSleep", new Class[]{Long.TYPE}).invoke(powerManager, new Object[]{Long.valueOf(SystemClock.uptimeMillis())});
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e2) {
            e2.printStackTrace();
        } catch (NoSuchMethodException e3) {
            e3.printStackTrace();
        }
    }

    @Deprecated
    public int setAutoDateTime(int i) {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return -1;
        }
        try {
            Settings.Global.putInt(context.getContentResolver(), "auto_time", i);
            return 0;
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }

    @Deprecated
    public String getSystemVersion() {
        return Build.VERSION.RELEASE;
    }

    @Deprecated
    public void wakeUp() {
        PowerManager powerManager = (PowerManager) this.mContext.getSystemService("power");
        try {
            powerManager.getClass().getMethod("wakeUp", new Class[]{Long.TYPE}).invoke(powerManager, new Object[]{Long.valueOf(SystemClock.uptimeMillis())});
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e2) {
            e2.printStackTrace();
        } catch (NoSuchMethodException e3) {
            e3.printStackTrace();
        }
    }

    @Deprecated
    public void shutDownSystem() {
        execRootCmdSilent("reboot -p");
    }

    @Deprecated
    public void rebootSystem() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        this.mContext.sendBroadcast(new Intent("reboot"));
        execRootCmdSilent("reboot");
    }

    @Deprecated
    public void recoverySystem() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        Intent intent = new Intent("android.intent.action.MASTER_CLEAR");
        intent.putExtra("isReformate", true);
        this.mContext.sendBroadcast(intent);
    }

    @Deprecated
    public void setOpenSystemBar() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        Intent intent = new Intent("com.ding.systembar.chang");
        intent.putExtra("enable", "0");
        this.mContext.sendBroadcast(intent);
    }

    @Deprecated
    public void setCloseSystemBar() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        Intent intent = new Intent("com.ding.systembar.chang");
        intent.putExtra("enable", "1");
        this.mContext.sendBroadcast(intent);
    }

    @Deprecated
    public int getSystemBarState() {
        return Integer.parseInt(getSystemProperty("persist.sys.barState", "1")) == 0 ? 1 : 0;
    }

    @Deprecated
    public void setOpenUsbDebug() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        Intent intent = new Intent("com.ding.adbsetting");
        intent.putExtra("enable", "1");
        this.mContext.sendBroadcast(intent);
    }

    @Deprecated
    public void setCloseUsbDebug() {
        if (this.mContext == null) {
            Log.e("上下文为空", "不执行");
            return;
        }
        Intent intent = new Intent("com.ding.adbsetting");
        intent.putExtra("enable", "0");
        this.mContext.sendBroadcast(intent);
    }

    @Deprecated
    public int getUsbDebugState() {
        return Integer.valueOf(getSystemProperty("persist.sys.adbState", "1")).intValue();
    }

    public void setSystemDate(int i, int i2, int i3) {
        LOGD("set system Date " + i + "/" + i2 + "/" + i3);
        Calendar instance = Calendar.getInstance();
        instance.set(1, i);
        instance.set(2, i2 - 1);
        instance.set(5, i3);
        SystemClock.setCurrentTimeMillis(instance.getTimeInMillis());
    }

    public void setSystemTime(int i, int i2, int i3, int i4) {
        LOGD("set system time " + i + ":" + i2);
        Calendar instance = Calendar.getInstance();
        instance.set(11, i);
        instance.set(12, i2);
        instance.set(13, i3);
        instance.set(14, i4);
        SystemClock.setCurrentTimeMillis(instance.getTimeInMillis());
    }

    @Deprecated
    public void setSystemDateAndTime(int i, int i2, int i3, int i4, int i5) {
        Calendar instance = Calendar.getInstance();
        instance.set(1, Integer.parseInt(String.valueOf(i)));
        instance.set(2, Integer.parseInt(String.valueOf(i2)) - 1);
        instance.set(5, Integer.parseInt(String.valueOf(i3)));
        instance.set(11, Integer.parseInt(String.valueOf(i4)));
        instance.set(12, Integer.parseInt(String.valueOf(i5)));
        SystemClock.setCurrentTimeMillis(instance.getTimeInMillis());
    }

    @Deprecated
    public int setAutoTimeZone(int i) {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return -1;
        }
        try {
            Settings.Global.putInt(context.getContentResolver(), "auto_time_zone", i);
            return 0;
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }

    @Deprecated
    public int setRaiseSystemBrightness() {
        return setSystemBrightness(getSystemBrightness() + 1);
    }

    @Deprecated
    public int setLowerSystemBrightness() {
        return setSystemBrightness(getSystemBrightness() - 1);
    }

    @Deprecated
    public int setSystemBrightness(int i) {
        Context context = this.mContext;
        if (context == null) {
            Log.e("上下文为空", "不执行");
            return -1;
        } else if (i < 0 || i > 255) {
            LOGD("brightness index 0~255 , please check it");
            return -1;
        } else {
            try {
                Settings.System.putInt(context.getContentResolver(), "screen_brightness", i);
                this.mContext.getContentResolver().notifyChange(Settings.System.getUriFor("screen_brightness"), (ContentObserver) null);
                return 0;
            } catch (Exception e) {
                try {
                    e.printStackTrace();
                    return 0;
                } catch (Exception e2) {
                    e2.printStackTrace();
                    return -1;
                }
            }
        }
    }

    @Deprecated
    public int getTpOrientation() {
        return Integer.valueOf(getSystemProperty(this.TP_ORIENTATION_PROP, "0")).intValue();
    }

    @Deprecated
    public void setTpOrientation(int i, boolean z) {
        if (i >= 0 && i <= 3) {
            try {
                setSystemProperty(this.TP_ORIENTATION_PROP, Integer.toString(i));
                if (z) {
                    execRootCmdSilent("reboot");
                }
            } catch (Exception unused) {
            }
        }
    }
}
