360手机助手 v3.3.0版本的 MD5 值为:127c345ad16bbebee6e347381328afd0

以下内容为反编译后的 de.java 源代码,内容仅作参考


package com.qihoo.appstore.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.IPackageManager;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
import android.content.pm.PackageStats;
import android.content.pm.Signature;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.ServiceManager;
import android.os.StatFs;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.provider.Settings;
import android.text.ClipboardManager;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.util.AndroidRuntimeException;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.Toast;
import com.qihoo.appstore.AppStoreApplication;
import com.qihoo.appstore.activities.MainActivity;
import com.qihoo.appstore.clear.ClearBackgroundHelper;
import com.qihoo.appstore.express.PushMessageHandle;
import com.qihoo.appstore.newadmin.NewAdminFragment;
import com.qihoo.appstore.resource.app.App;
import com.qihoo.freewifi.push.R;
import com.qihoo.freewifi.push.download.DownloadUtils;
import com.qihoo.speedometer.Config;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.Character;
import java.lang.reflect.InvocationTargetException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.json.JSONObject;

public class de {

    public static boolean f3814a = false;

    public static boolean f3815b;
    public static DisplayMetrics c;
    public static final Pattern d;
    private static long e;
    private static final char[] f;
    private static SharedPreferences g;
    private static String h;
    private static String i;
    private static String j;
    private static String k;
    private static AlertDialog l;
    private static String m;
    private static final String[] n;
    private static final String[] o;

    static {
        f3815b = Build.VERSION.SDK_INT >= 9;
        e = 0L;
        f = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
        h = "pref_key_hotwords";
        i = "-1";
        j = "pref_key_user_info";
        k = "pref_key_user_exp_plan";
        c = null;
        l = null;
        m = "pref_key_push_info";
        n = new String[]{"display_name", "contact_id", "data1", "sort_key"};
        o = new String[]{"display_name", "contact_id", "data1"};
        d = Pattern.compile(".*[0-9]{1}$");
    }

    public static int A(Context context) {
        if (g == null) {
            g = PreferenceManager.getDefaultSharedPreferences(context);
        }
        return g.getInt("start_count", 1);
    }

    public static Map B(Context context) {
        String upperCase;
        HashMap hashMap = new HashMap();
        try {
            ContentResolver contentResolver = context.getContentResolver();
            if (contentResolver != null) {
                Cursor query = Build.VERSION.SDK_INT >= 11 ? contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, n, null, null, "display_name ASC") : contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, o, null, null, "display_name ASC");
                int i2 = 0;
                while (query.moveToNext()) {
                    String string = query.getString(0);
                    int i3 = query.getInt(1);
                    String string2 = query.getString(2);
                    if (Build.VERSION.SDK_INT >= 11) {
                        String upperCase2 = query.getString(3).substring(0, 1).toUpperCase();
                        upperCase = (upperCase2.compareTo("A") < 0 || upperCase2.compareTo("Z") > 0) ? "#" : upperCase2;
                    } else {
                        upperCase = m.c(string).toUpperCase();
                    }
                    if (!TextUtils.isEmpty(string2)) {
                        com.qihoo.appstore.sharenearby.n nVar = new com.qihoo.appstore.sharenearby.n();
                        nVar.f3354a = i2;
                        nVar.f3355b = i3;
                        nVar.c = string;
                        nVar.d = string2;
                        nVar.e = upperCase;
                        List list = (List) hashMap.get(upperCase);
                        if (list == null) {
                            list = new ArrayList();
                            hashMap.put(upperCase, list);
                        }
                        list.add(nVar);
                        i2++;
                    }
                }
                query.close();
                return hashMap;
            }
        } catch (Exception e2) {
        }
        return null;
    }

    public static void C(Context context) {
        new Timer().schedule(new dj(context), 100L);
    }

    public static boolean D(Context context) {
        return "1".equals(Settings.Secure.getString(context.getContentResolver(), "adb_enabled"));
    }

    public static void E(Context context) {
        if (context != null) {
            try {
                Intent intent = new Intent();
                intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.DevelopmentSettings"));
                intent.setAction("android.intent.action.VIEW");
                intent.addFlags(268435456);
                context.startActivity(intent);
            } catch (ActivityNotFoundException e2) {
                try {
                    Intent intent2 = new Intent();
                    intent2.setComponent(new ComponentName("com.android.settings", "com.android.settings.ApplicationSettings"));
                    context.startActivity(intent2);
                } catch (Exception e3) {
                    e3.printStackTrace();
                    Toast.makeText(context, "启动失败,没有找到开发者设置", 0).show();
                }
            } catch (SecurityException e4) {
                Toast.makeText(context, "启动失败,没有权限启动开发者设置页面", 0).show();
            } catch (Exception e5) {
                e5.printStackTrace();
                Toast.makeText(context, "启动失败,未知错误", 0).show();
            }
        }
    }

    public static void F(Context context) {
        PackageInfo packageInfo = null;
        try {
            packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e2) {
            e2.printStackTrace();
        }
        Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
        intent.setClassName("com.android.settings", "com.miui.securitycenter.permission.AppPermissionsEditor");
        intent.putExtra("extra_package_uid", packageInfo.applicationInfo.uid);
        try {
            context.startActivity(intent);
        } catch (Exception e3) {
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                bk.a(DownloadUtils.TAG, Config.INVALID_IP, e3);
            }
        }
    }

    public static int a(float f2) {
        return (int) ((b().density * f2) + 0.5f);
    }

    public static int a(int... iArr) {
        boolean z = true;
        int length = iArr.length;
        if (length == 1) {
            return iArr[0];
        }
        int i2 = 0;
        int i3 = 0;
        while (i2 < length) {
            if (z) {
                i3 = Math.min(iArr[i2], iArr[i2 + 1]);
                z = false;
            }
            int min = Math.min(i3, iArr[i2]);
            i2++;
            i3 = min;
        }
        if (!com.qihoo360.mobilesafe.a.a.f5313a) {
            return i3;
        }
        bk.b(DownloadUtils.TAG, " ---> min = " + i3);
        return i3;
    }

    public static long a(long j2) {
        return j2 < 3000000 ? (j2 * 2) + 1000000 : j2 < ((long) 10000000) ? (j2 * 2) + 3000000 : (j2 * 2) + 10000000;
    }

    public static PackageParser.Package a(String str, int i2) {
        PackageParser.Package r0 = null;
        PackageParser packageParser = new PackageParser(str);
        DisplayMetrics displayMetrics = new DisplayMetrics();
        displayMetrics.setToDefaults();
        try {
            PackageParser.Package parsePackage = packageParser.parsePackage(new File(str), str, displayMetrics, i2);
            if (parsePackage != null) {
                packageParser.collectCertificates(parsePackage, 1);
                r0 = parsePackage;
            } else if (com.qihoo360.mobilesafe.a.a.f5313a) {
                bk.b(DownloadUtils.TAG, "---parsePackage is null------");
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        return r0;
    }

    public static String a(Context context, int i2) {
        if (i2 == -1) {
            return null;
        }
        if (i2 < 1000) {
            return context.getString(R.string.app_list_item_week_count_less1000_format);
        }
        if (1000 > i2 || i2 >= 10000) {
            int i3 = i2 / 10000;
            if (i2 % 10000 >= 5000) {
                i3++;
            }
            return String.format(context.getString(R.string.app_list_item_week_count_big_format), Integer.valueOf(i3));
        }
        int i4 = i2 / 1000;
        if (i2 % 1000 >= 500) {
            i4++;
        }
        return String.format(context.getString(R.string.app_list_item_week_count_small_format), Integer.valueOf(i4 <= 9 ? i4 : 9));
    }

    public static String a(Context context, long j2) {
        return Formatter.formatFileSize(context, j2).replaceAll("B", Config.INVALID_IP);
    }

    public static final String a(Context context, String str) {
        InputStream inputStream;
        InputStream inputStream2;
        String str2;
        BufferedReader bufferedReader = null;
        InputStream inputStream3 = null;
        BufferedReader bufferedReader2 = null;
        try {
            try {
                if (TextUtils.isEmpty(str)) {
                    if (0 != 0) {
                        inputStream3.close();
                    }
                    if (0 == 0) {
                        return Config.INVALID_IP;
                    }
                    bufferedReader2.close();
                    return Config.INVALID_IP;
                }
                inputStream = context.getResources().getAssets().open("conf");
                try {
                    BufferedReader bufferedReader3 = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
                    while (true) {
                        try {
                            String readLine = bufferedReader3.readLine();
                            if (readLine == null) {
                                if (inputStream != null) {
                                    try {
                                        inputStream.close();
                                    } catch (IOException e2) {
                                    }
                                }
                                if (bufferedReader3 != null) {
                                    bufferedReader3.close();
                                }
                                return Config.INVALID_IP;
                            }
                            String trim = readLine.trim();
                            if (!trim.startsWith("#")) {
                                int indexOf = trim.indexOf(35);
                                if (indexOf >= 0) {
                                    trim = trim.substring(0, indexOf);
                                }
                                int indexOf2 = trim.indexOf(61);
                                if (indexOf2 >= 0) {
                                    String trim2 = trim.substring(0, indexOf2).trim();
                                    String trim3 = trim.substring(indexOf2 + 1).trim();
                                    if (str.equalsIgnoreCase(trim2)) {
                                        if (inputStream != null) {
                                            inputStream.close();
                                        }
                                        if (bufferedReader3 == null) {
                                            return trim3;
                                        }
                                        bufferedReader3.close();
                                        return trim3;
                                    }
                                } else {
                                    continue;
                                }
                            }
                        } catch (IOException e3) {
                            bufferedReader = bufferedReader3;
                            inputStream2 = inputStream;
                            if (inputStream2 != null) {
                                inputStream2.close();
                            }
                            if (bufferedReader == null) {
                                return Config.INVALID_IP;
                            }
                            bufferedReader.close();
                            return Config.INVALID_IP;
                        } catch (Throwable th) {
                            th = th;
                            bufferedReader = bufferedReader3;
                            if (inputStream != null) {
                                try {
                                    inputStream.close();
                                } catch (IOException e4) {
                                    throw th;
                                }
                            }
                            if (bufferedReader != null) {
                                bufferedReader.close();
                            }
                            throw th;
                        }
                    }
                } catch (IOException e5) {
                    inputStream2 = inputStream;
                } catch (Throwable th2) {
                    th = th2;
                }
            } catch (IOException e6) {
                return str2;
            }
        } catch (IOException e7) {
            inputStream2 = null;
        } catch (Throwable th3) {
            th = th3;
            inputStream = null;
        }
    }

    public static String a(Resources resources, int i2) {
        switch (i2) {
            case 406:
                return resources.getString(R.string.download_not_acceptable);
            case 411:
                return resources.getString(R.string.download_length_required);
            case 412:
                return resources.getString(R.string.download_precondition_failed);
            case 490:
                return resources.getString(R.string.download_canceled);
            case 492:
                return resources.getString(R.string.download_error);
            case 493:
                return resources.getString(R.string.merge_error);
            case 495:
            case 496:
                return resources.getString(R.string.download_network_error);
            default:
                return resources.getString(R.string.download_error);
        }
    }

    public static String a(String str, String str2) {
        UnsupportedEncodingException e2;
        String str3;
        if (str == null || str.length() == 0) {
            return null;
        }
        String[] split = str.split("&");
        for (int i2 = 0; i2 < split.length; i2++) {
            for (int i3 = 0; i3 < split.length; i3++) {
                if (split[i2].compareTo(split[i3]) < 0) {
                    String str4 = split[i2];
                    split[i2] = split[i3];
                    split[i3] = str4;
                }
            }
        }
        String str5 = Config.INVALID_IP;
        for (String str6 : split) {
            str5 = str5 + str6;
        }
        String str7 = str5 + str2;
        try {
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                bk.b("MD5", "MD5 before= " + str7);
            }
            String i4 = i(str7);
            try {
                str3 = i4.toLowerCase();
            } catch (UnsupportedEncodingException e3) {
                e2 = e3;
                str3 = i4;
            }
        } catch (UnsupportedEncodingException e4) {
            e2 = e4;
            str3 = null;
        }
        try {
            if (!com.qihoo360.mobilesafe.a.a.f5313a) {
                return str3;
            }
            bk.b("MD5", "MD5 after= " + str3);
            return str3;
        } catch (UnsupportedEncodingException e5) {
            e2 = e5;
            e2.printStackTrace();
            return str3;
        }
    }

    public static String a(byte[] bArr) {
        StringBuilder sb = new StringBuilder(bArr.length * 2);
        for (int i2 = 0; i2 < bArr.length; i2++) {
            sb.append(f[(bArr[i2] & 240) >>> 4]);
            sb.append(f[bArr[i2] & 15]);
        }
        return sb.toString();
    }

    public static final Comparator a() {
        return new df();
    }

    public static void a(Activity activity, boolean z) {
        View inflate = activity.getLayoutInflater().inflate(R.layout.exit_dialog, (ViewGroup) activity.findViewById(R.layout.exit_dialog));
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setIcon(R.drawable.logo).setTitle(R.string.Infotip).setView(inflate);
        if (!z) {
            long currentTimeMillis = System.currentTimeMillis();
            if (currentTimeMillis - e > Config.MIN_TIME_BETWEEN_MEASUREMENT_ALARM_MSEC) {
                activity.runOnUiThread(new dg(activity));
                e = currentTimeMillis;
                return;
            }
            com.qihoo.appstore.personnalcenter.friends.x.d();
            com.qihoo.appstore.personnalcenter.friends.am.b();
            NewAdminFragment.f2123a = false;
            a((Context) activity, true);
            activity.finish();
            com.qihoo.appstore.f.g.o();
            PushMessageHandle.k();
            return;
        }
        builder.setMessage(R.string.ExitMessageCompletely);
        CheckBox checkBox = (CheckBox) inflate.findViewById(R.id.chkClearCache);
        boolean c2 = f.c("clear_cache_checked", false);
        if (checkBox != null) {
            checkBox.setChecked(c2);
        }
        CheckBox checkBox2 = (CheckBox) inflate.findViewById(R.id.chkKeepDownload);
        checkBox2.setVisibility(8);
        a((Context) activity, false);
        checkBox2.setPadding(((int) ((activity.getResources().getDisplayMetrics().density * 10.0f) + 0.5f)) + checkBox2.getPaddingLeft(), checkBox2.getPaddingTop(), checkBox2.getPaddingRight(), checkBox2.getPaddingBottom());
        if (checkBox2 != null) {
            checkBox2.setChecked(a(activity));
        }
        dh dhVar = new dh(checkBox, checkBox2, activity);
        checkBox.setOnCheckedChangeListener(dhVar);
        checkBox2.setOnCheckedChangeListener(dhVar);
        builder.setPositiveButton(R.string.Ok, new di(z));
        builder.setNegativeButton(R.string.Cancel, (DialogInterface.OnClickListener) null);
        builder.create().show();
    }

    public static void a(Context context, NotificationManager notificationManager, int i2, Notification notification) {
        a(context, notificationManager, i2, notification, false);
    }

    public static void a(Context context, NotificationManager notificationManager, int i2, Notification notification, boolean z) {
        if (z) {
            notificationManager.cancel(i2);
        }
        if (context.getResources().getDrawable(notification.icon) == null) {
            bk.d(DownloadUtils.TAG, " --> get notification icon drawable failed, give up the notification");
            return;
        }
        try {
            notificationManager.notify(i2, notification);
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    public static void a(Context context, View view) {
        ((InputMethodManager) context.getSystemService("input_method")).hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    public static void a(Context context, String str, String str2, String str3, String str4, String str5) {
        Intent intent = new Intent("android.intent.action.SEND");
        intent.setType(str5);
        intent.putExtra("android.intent.extra.TEXT", str2);
        if (str4 != null) {
            File file = new File(str4);
            if (file.exists()) {
                intent.putExtra("android.intent.extra.STREAM", Uri.fromFile(file));
            }
        }
        try {
            context.startActivity(Intent.createChooser(intent, str3));
        } catch (Exception e2) {
            Toast.makeText(context, R.string.send_share_intent_error, 0).show();
        }
    }

    public static void a(Context context, String str, boolean z) {
        f.b(str, z);
    }

    public static void a(Context context, boolean z) {
        f.b("pref_key_keep_download", z);
    }

    public static boolean a(char c2) {
        Character.UnicodeBlock of = Character.UnicodeBlock.of(c2);
        return of == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || of == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS || of == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A || of == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B || of == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION || of == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS || of == Character.UnicodeBlock.GENERAL_PUNCTUATION;
    }

    public static boolean a(int i2, int i3) {
        return i2 > i3;
    }

    public static boolean a(Context context) {
        return f.c("pref_key_keep_download", true);
    }

    public static boolean a(Context context, App app) {
        try {
            return a(context, f(context, app.W()), app.bK());
        } catch (Exception e2) {
            if (!com.qihoo360.mobilesafe.a.a.f5313a) {
                return true;
            }
            bk.b(DownloadUtils.TAG, "--get exception=" + e2.toString());
            return true;
        }
    }

    public static boolean a(Context context, String str, String str2) {
        if (com.qihoo360.mobilesafe.a.a.f5313a) {
            bk.b(DownloadUtils.TAG, "---urlSignatureMd5=" + str2 + ",localSignatureMd5=" + str);
        }
        if (str2 == null || str == null) {
            return true;
        }
        try {
            if (Config.INVALID_IP.equals(str2) || Config.INVALID_IP.equals(str)) {
                return true;
            }
            return str2.equals(str);
        } catch (Exception e2) {
            if (!com.qihoo360.mobilesafe.a.a.f5313a) {
                return true;
            }
            bk.b(DownloadUtils.TAG, "--get exception=" + e2.toString());
            return true;
        }
    }

    public static boolean a(File file) {
        if (file == null) {
            return false;
        }
        if (file.isDirectory()) {
            for (String str : file.list()) {
                if (!a(new File(file, str))) {
                    return false;
                }
            }
        }
        return file.delete();
    }

    public static boolean a(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        File file = new File(str);
        if (file.exists()) {
            return true;
        }
        return file.mkdirs();
    }

    public static boolean a(JSONObject jSONObject) {
        try {
            String b2 = b(jSONObject.getString("errno"));
            if (b2.equals("0")) {
                return true;
            }
            return b2.equals("ok");
        } catch (Exception e2) {
            e2.printStackTrace();
            return true;
        }
    }

    public static byte[] a(InputStream inputStream) {
        byte[] bArr = new byte[1024];
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            while (true) {
                int read = inputStream.read(bArr);
                if (read == -1) {
                    byteArrayOutputStream.close();
                    inputStream.close();
                    return byteArrayOutputStream.toByteArray();
                }
                byteArrayOutputStream.write(bArr, 0, read);
            }
        } catch (OutOfMemoryError e2) {
            System.gc();
            e2.printStackTrace();
            return null;
        }
    }

    public static Signature[] a(PackageParser.Package r4, String str) {
        if (com.qihoo360.mobilesafe.a.a.f5313a) {
            bk.b(DownloadUtils.TAG, "==================================apkPath=" + str);
        }
        Signature[] signatureArr = r4.mSignatures;
        if (signatureArr != null && signatureArr.length > 0) {
            return signatureArr;
        }
        return null;
    }

    public static long b(Context context) {
        File cacheDir = context.getCacheDir();
        if (!c(cacheDir.getParent())) {
            return ClearBackgroundHelper.SIZE_K;
        }
        if (com.qihoo360.mobilesafe.a.a.f5313a) {
            bk.b(DownloadUtils.TAG, "read rom  path=:" + cacheDir.getParent());
        }
        StatFs statFs = new StatFs(cacheDir.getParent());
        return (statFs.getAvailableBlocks() * statFs.getBlockSize()) / ClearBackgroundHelper.SIZE_K;
    }

    public static DisplayMetrics b() {
        if (c == null) {
            c = AppStoreApplication.d().getResources().getDisplayMetrics();
        }
        return c;
    }

    public static String b(Context context, long j2) {
        float f2;
        String str;
        if (context == null) {
            return Config.INVALID_IP;
        }
        if (j2 <= ClearBackgroundHelper.SIZE_K) {
            return j2 + "B";
        }
        if (j2 <= 10240) {
            return (j2 / ClearBackgroundHelper.SIZE_K) + "KB";
        }
        float f3 = (((float) j2) * 1.0f) / 1048576.0f;
        if (f3 > 900.0f) {
            f2 = f3 / 1024.0f;
            str = "G";
        } else {
            f2 = f3;
            str = "M";
        }
        return (f2 < 1.0f ? String.format("%.2f", Float.valueOf(f2)) : f2 < 10.0f ? String.format("%.2f", Float.valueOf(f2)) : f2 < 100.0f ? String.format("%.2f", Float.valueOf(f2)) : String.format("%.2f", Float.valueOf(f2))) + str;
    }

    public static String b(Resources resources, int i2) {
        if (com.qihoo.appstore.f.cw.c(i2)) {
            return a(resources, i2);
        }
        switch (i2) {
            case 190:
                return resources.getString(R.string.download_pending);
            case 191:
            default:
                return resources.getString(R.string.download_running_paused);
            case 192:
                return resources.getString(R.string.download_running);
        }
    }

    public static String b(String str) {
        StringBuilder sb = new StringBuilder();
        int length = str.length();
        for (int i2 = 0; i2 < length; i2++) {
            char charAt = str.charAt(i2);
            if (charAt >= '0' && charAt <= '9') {
                sb.append(charAt);
            }
        }
        return sb.toString().length() <= 0 ? "0" : sb.toString();
    }

    public static void b(Context context, boolean z) {
        f.b("pref_key_has_created_shortcut_131", z);
    }

    public static boolean b(long j2) {
        return (com.qihoo.appstore.l.b.a.b() ? k(Environment.getExternalStorageDirectory().getPath()) : k(Environment.getDataDirectory().getPath())) > j2;
    }

    public static boolean b(Context context, String str) {
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(str, 0);
            if (packageInfo.packageName.equals(str)) {
                return (packageInfo.applicationInfo.flags & 1) > 0;
            }
            return false;
        } catch (PackageManager.NameNotFoundException e2) {
            if (!com.qihoo360.mobilesafe.a.a.f5313a) {
                return false;
            }
            bk.b(DownloadUtils.TAG, "-------App No Installed-----------");
            return false;
        }
    }

    public static boolean b(Context context, String str, boolean z) {
        return f.c(str, z);
    }

    public static int c(Context context, String str) {
        try {
            return context.getPackageManager().getPackageInfo(str, 0).versionCode;
        } catch (Exception e2) {
            e2.printStackTrace();
            return -1;
        }
    }

    public static long c(Context context) {
        if (!com.qihoo.appstore.l.b.a.b()) {
            return Long.MAX_VALUE;
        }
        File externalStorageDirectory = Environment.getExternalStorageDirectory();
        if (!c(externalStorageDirectory.getPath())) {
            return ClearBackgroundHelper.SIZE_K;
        }
        if (com.qihoo360.mobilesafe.a.a.f5313a) {
            bk.b(DownloadUtils.TAG, "readSDCard path=:" + externalStorageDirectory.getPath());
        }
        StatFs statFs = new StatFs(externalStorageDirectory.getPath());
        return (statFs.getAvailableBlocks() * statFs.getBlockSize()) / ClearBackgroundHelper.SIZE_K;
    }

    public static String c(Context context, long j2) {
        float f2;
        String str;
        if (context == null) {
            return Config.INVALID_IP;
        }
        if (j2 <= ClearBackgroundHelper.SIZE_K) {
            return j2 + "B";
        }
        if (j2 <= 10240) {
            return (j2 / ClearBackgroundHelper.SIZE_K) + "KB";
        }
        float f3 = (((float) j2) * 1.0f) / 1048576.0f;
        if (f3 > 900.0f) {
            f2 = f3 / 1024.0f;
            str = "G";
        } else {
            f2 = f3;
            str = "M";
        }
        return (f2 < 1.0f ? String.format("%.1f", Float.valueOf(f2)) : f2 < 10.0f ? String.format("%.1f", Float.valueOf(f2)) : f2 < 100.0f ? String.format("%.1f", Float.valueOf(f2)) : String.format("%.1f", Float.valueOf(f2))) + str;
    }

    public static void c() {
        App app = new App();
        app.d(1);
        app.o(AppStoreApplication.d().getString(R.string.qvod));
        app.m("com.qvod.player");
        app.s("http://p7.qhimg.com/t01675221857950f5a8.png");
        com.qihoo.appstore.f.g.a((com.qihoo.appstore.e.a.b) app, true, false);
    }

    public static void c(Context context, String str, boolean z) {
        f.b(str, z);
    }

    public static void c(Context context, boolean z) {
        f.b(k, z);
    }

    public static boolean c(String str) {
        return !TextUtils.isEmpty(str) && new File(str).exists();
    }

    public static long d(Context context) {
        if (com.qihoo.appstore.l.b.a.b()) {
            return c(context) * ClearBackgroundHelper.SIZE_K;
        }
        return 0L;
    }

    public static String d(Context context, long j2) {
        return j2 > 10000 ? String.format(context.getString(R.string.app_list_item_download_count_large_format), Long.valueOf(j2 / 10000)) : String.format(context.getString(R.string.app_list_item_download_count_small_format), Long.valueOf(j2));
    }

    public static void d() {
        App app = new App();
        app.d(1);
        app.o(AppStoreApplication.d().getString(R.string._360_movies_all));
        app.m("com.qihoo.video");
        app.s("http://p19.qhimg.com/t0113fd57fbb3e42128.png");
        com.qihoo.appstore.f.g.a((com.qihoo.appstore.e.a.b) app, true, false);
    }

    public static void d(Context context, String str) {
        if (str != null && !Config.INVALID_IP.equals(str)) {
            str = q.a(context, str);
        }
        if (com.qihoo360.mobilesafe.a.a.f5313a) {
            bk.b("UserInfo", "saveUserInfo,pref_key_user_info:" + str);
        }
        f.b(j, str);
    }

    public static void d(Context context, boolean z) {
        f.b("perf_key_show_help_new_icon", z);
    }

    public static boolean d(String str) {
        try {
            if (!TextUtils.isEmpty(str)) {
                File file = new File(str);
                if (file.exists()) {
                    file.delete();
                    return true;
                }
            }
        } catch (Exception e2) {
        }
        return false;
    }

    public static long e(Context context) {
        return b(context) * ClearBackgroundHelper.SIZE_K;
    }

    public static String e() {
        return new SimpleDateFormat("yyyy-MM-dd").format(Long.valueOf(System.currentTimeMillis()));
    }

    public static String e(Context context, String str) {
        try {
            return aw.a(context.getPackageManager().getPackageInfo(str, 64).signatures[0].toByteArray());
        } catch (Exception e2) {
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                e2.printStackTrace();
            }
            return null;
        }
    }

    public static String e(String str) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(str.getBytes());
            return a(messageDigest.digest());
        } catch (NoSuchAlgorithmException e2) {
            e2.printStackTrace();
            return str;
        }
    }

    public static boolean e(Context context, long j2) {
        if (com.qihoo.appstore.l.b.a.b()) {
            if (j2 > c(context) * ClearBackgroundHelper.SIZE_K) {
                if (com.qihoo360.mobilesafe.a.a.f5313a) {
                    bk.b(DownloadUtils.TAG, "--app size=" + j2 + ",SDCard AvailableSize=" + c(context));
                }
                if (!com.qihoo360.mobilesafe.a.a.f5313a) {
                    return true;
                }
                bk.b(DownloadUtils.TAG, "----------SDCard not enough space----------");
                return true;
            }
        } else if (j2 > b(context) * ClearBackgroundHelper.SIZE_K) {
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                bk.b(DownloadUtils.TAG, "--app size=" + j2 + ",SDCard AvailableSize=" + b(context));
            }
            if (!com.qihoo360.mobilesafe.a.a.f5313a) {
                return true;
            }
            bk.b(DownloadUtils.TAG, "----------system rom not enough space----------");
            return true;
        }
        return false;
    }

    public static String f(Context context) {
        try {
            String format = String.format("%s", context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName);
            if (format != null) {
                if (format.length() != 0) {
                    return format;
                }
            }
        } catch (PackageManager.NameNotFoundException e2) {
            e2.printStackTrace();
        }
        return Config.INVALID_IP;
    }

    public static String f(Context context, String str) {
        try {
            return e(Arrays.toString(context.getPackageManager().getPackageInfo(str, 64).signatures[0].toByteArray())).toLowerCase();
        } catch (Exception e2) {
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                e2.printStackTrace();
            }
            return null;
        }
    }

    public static boolean f(Context context, long j2) {
        com.qihoo.appstore.http.netconfig.f a2 = com.qihoo.appstore.http.netconfig.g.a(context);
        return (a2.a() == 1 || a2.a() == -1 || a2.e() == -1 || j2 < a2.e()) ? false : true;
    }

    public static boolean f(String str) {
        return Pattern.compile("^[A-Za-z0-9]+([._+-]*[A-Za-z0-9])*@([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])(\\.{1,3}[A-Za-z]{2,6}){1,2}$").matcher(str).matches();
    }

    public static String g(Context context, long j2) {
        return j2 > 10000 ? String.format(context.getString(R.string.app_list_item_download_count_large_format1), Long.valueOf(j2 / 10000)) : String.format(context.getString(R.string.app_list_item_download_count_small_format1), Long.valueOf(j2));
    }

    public static String g(String str) {
        return a(str, "973dbf24m");
    }

    public static boolean g(Context context) {
        return f.c("pref_key_has_created_shortcut_131", false);
    }

    public static String[] g(Context context, String str) {
        PackageParser.Package r0;
        try {
            String[] p = p(context, str);
            if (p != null) {
                return p;
            }
            try {
                r0 = a(str, 64);
            } catch (OutOfMemoryError e2) {
                r0 = null;
            }
            if (r0 == null) {
                if (com.qihoo360.mobilesafe.a.a.f5313a) {
                    bk.b(DownloadUtils.TAG, "PackageParser.Package is null");
                }
                return null;
            }
            Signature[] a2 = a(r0, str);
            if (a2 == null || a2.length <= 0) {
                return null;
            }
            return new String[]{e(Arrays.toString(a2[0].toByteArray())).toLowerCase(), r0.applicationInfo.packageName};
        } catch (Exception e3) {
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                e3.printStackTrace();
            }
            return null;
        }
    }

    public static final String h(Context context) {
        String str;
        try {
            if (Build.VERSION.SDK_INT >= 8) {
                str = context.getPackageCodePath();
            } else {
                try {
                    str = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.publicSourceDir;
                } catch (PackageManager.NameNotFoundException e2) {
                    e2.printStackTrace();
                    str = Config.INVALID_IP;
                }
            }
            String a2 = com.qihoo.a.d.a(str);
            if (a2 != null && (a2.matches("qch_np_\\d+_gs\\d+.*") || a2.matches("np_\\d+_gs\\d+.*"))) {
                Matcher matcher = Pattern.compile("\\d+").matcher(a2);
                if (matcher.find() && matcher.find()) {
                    String group = matcher.group();
                    if (!TextUtils.isEmpty(group)) {
                        return group;
                    }
                }
            }
            return null;
        } catch (Throwable th) {
            th.printStackTrace();
            return null;
        }
    }

    public static String h(String str) {
        String[] split = str.split("&");
        for (int i2 = 0; i2 < split.length; i2++) {
            for (int i3 = 0; i3 < split.length; i3++) {
                if (split[i2].compareTo(split[i3]) < 0) {
                    String str2 = split[i2];
                    split[i2] = split[i3];
                    split[i3] = str2;
                }
            }
        }
        StringBuffer stringBuffer = new StringBuffer();
        int length = split.length;
        for (int i4 = 0; i4 < length; i4++) {
            stringBuffer.append(split[i4]);
            if (i4 < length - 1) {
                stringBuffer.append("&");
            }
        }
        return stringBuffer.toString();
    }

    public static boolean h(Context context, String str) {
        return f.c(str, false);
    }

    public static String i(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("zy_channel", 0);
        String string = sharedPreferences.getString("channel_id", null);
        if (sharedPreferences.contains("channel_id") && !TextUtils.isEmpty(string)) {
            return string;
        }
        String j2 = j(context);
        com.qihoo360.mobilesafe.util.ag.a(sharedPreferences.edit().putString("channel_id", j2));
        return j2;
    }

    public static String i(String str) {
        return URLEncoder.encode(e(str), "UTF-8");
    }

    public static void i(Context context, String str) {
        f.b("sava_the_feedback_mail", str);
    }

    public static long j(String str) {
        if (TextUtils.isEmpty(str)) {
            return -1L;
        }
        try {
            StatFs statFs = new StatFs(str);
            return statFs.getBlockCount() * statFs.getBlockSize();
        } catch (Exception e2) {
            if (!com.qihoo360.mobilesafe.a.a.f5313a) {
                return -1L;
            }
            bk.a(DownloadUtils.TAG, "获取内存空间:", e2);
            return -1L;
        }
    }

    public static String j(Context context) {
        String str;
        if (!"-1".equals(i)) {
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                bk.b(DownloadUtils.TAG, "readChannel from cache, return " + i);
            }
            return i;
        }
        long currentTimeMillis = System.currentTimeMillis();
        try {
            str = com.qihoo.a.d.a(Build.VERSION.SDK_INT >= 8 ? context.getPackageCodePath() : context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.publicSourceDir);
            if (str == null || !str.matches("\\d+")) {
                if (str != null && str.startsWith("err")) {
                    str = null;
                }
                if (str != null && str.startsWith("qch_np_")) {
                    str = str.substring("qch_np_".length());
                }
                if (str != null && str.startsWith("qch_")) {
                    str = str.substring("qch_".length());
                }
                if (str != null && !str.matches("\\d+")) {
                    throw new AndroidRuntimeException("无效的渠道号");
                }
            }
        } catch (Throwable th) {
            str = null;
        }
        if (TextUtils.isEmpty(str)) {
            str = a(context, "cid");
        }
        i = str;
        if (!com.qihoo360.mobilesafe.a.a.f5313a) {
            return str;
        }
        bk.b(DownloadUtils.TAG, "readChannel cost " + (System.currentTimeMillis() - currentTimeMillis) + "ms, return " + str);
        return str;
    }

    public static void j(Context context, String str) {
        Intent intent = new Intent("QvodPlayer.VIDEO_PLAY_ACTION");
        intent.addFlags(268435456);
        intent.setDataAndType(Uri.parse(str), "video/*");
        context.startActivity(intent);
    }

    public static long k(String str) {
        if (TextUtils.isEmpty(str)) {
            return -1L;
        }
        try {
            StatFs statFs = new StatFs(str);
            return statFs.getAvailableBlocks() * statFs.getBlockSize();
        } catch (Exception e2) {
            if (!com.qihoo360.mobilesafe.a.a.f5313a) {
                return -1L;
            }
            bk.a(DownloadUtils.TAG, "获取内存空间:", e2);
            return -1L;
        }
    }

    public static void k(Context context, String str) {
        Uri parse = Uri.parse(str);
        if (parse != null) {
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.setData(parse);
            intent.addFlags(268435456);
            context.startActivity(intent);
        }
    }

    public static final boolean k(Context context) {
        return "t".equalsIgnoreCase(a(context, "server"));
    }

    public static void l(Context context, String str) {
        f.a(str, e());
    }

    public static final boolean l(Context context) {
        return "t".equalsIgnoreCase(a(context, "l"));
    }

    public static boolean l(String str) {
        return Pattern.compile("^[a-zA-Z_]\\w*(\\.[a-zA-Z_]\\w*)*$").matcher(str).matches();
    }

    public static String m(Context context) {
        String d2 = f.d(j, null);
        if (com.qihoo360.mobilesafe.a.a.f5313a) {
            bk.b("UserInfo", "initial pref_key_user_info:" + d2);
        }
        if (d2 == null || Config.INVALID_IP.equals(d2)) {
            if (com.qihoo360.mobilesafe.a.a.f5313a) {
                bk.b("UserInfo", "pref_key_user_info is null:" + d2);
            }
            return g.getString(j, null);
        }
        if (!q.c(context, d2)) {
            d(context, d2);
            d2 = q.a(context, d2);
        }
        if (com.qihoo360.mobilesafe.a.a.f5313a) {
            bk.b("UserInfo", "Decode before ,pref_key_user_info:" + d2);
        }
        String b2 = q.b(context, d2);
        if (!com.qihoo360.mobilesafe.a.a.f5313a) {
            return b2;
        }
        bk.b("UserInfo", "Decode after ,pref_key_user_info:" + b2);
        return b2;
    }

    public static String m(String str) {
        return str.replaceAll("\b|\t|\n|\r\n|\f|\r", Config.INVALID_IP);
    }

    public static final boolean m(Context context, String str) {
        try {
            return context.getPackageManager().getPackageInfo(str, 0) != null;
        } catch (PackageManager.NameNotFoundException e2) {
            return false;
        }
    }

    public static final PackageStats n(Context context, String str) {
        try {
            e eVar = new e();
            AtomicReference atomicReference = new AtomicReference();
            eVar.b();
            context.getPackageManager().getPackageSizeInfo(str, new dk(atomicReference, eVar));
            eVar.d();
            return (PackageStats) atomicReference.get();
        } catch (Exception e2) {
            return null;
        }
    }

    public static void n(Context context) {
        if (context != null) {
            try {
                if (MainActivity.e() == null || MainActivity.e().getCurrentFocus() == null) {
                    return;
                }
                ((InputMethodManager) context.getSystemService("input_method")).hideSoftInputFromWindow(MainActivity.e().getCurrentFocus().getWindowToken(), 2);
            } catch (Exception e2) {
            }
        }
    }

    public static boolean n(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        try {
            ((ClipboardManager) AppStoreApplication.d().getSystemService("clipboard")).setText(str);
            return true;
        } catch (Exception e2) {
            return false;
        }
    }

    public static long o(Context context, String str) {
        PackageStats n2 = n(context, str);
        if (n2 != null) {
            return n2.cacheSize + n2.dataSize;
        }
        return -1L;
    }

    public static Boolean o(Context context) {
        return Boolean.valueOf(f.c(k, true));
    }

    public static String o(String str) {
        BufferedInputStream bufferedInputStream;
        BufferedInputStream bufferedInputStream2 = null;
        StringBuilder sb = new StringBuilder();
        byte[] bArr = new byte[1024];
        try {
            try {
                bufferedInputStream = new BufferedInputStream(new FileInputStream(new File(str)));
                while (true) {
                    try {
                        try {
                            int read = bufferedInputStream.read(bArr);
                            if (read == -1) {
                                break;
                            }
                            sb.append(new String(bArr, 0, read));
                        } catch (IOException e2) {
                            e = e2;
                            e.printStackTrace();
                            if (bufferedInputStream != null) {
                                bufferedInputStream.close();
                            }
                            return sb.toString();
                        }
                    } catch (Throwable th) {
                        th = th;
                        bufferedInputStream2 = bufferedInputStream;
                        if (bufferedInputStream2 != null) {
                            try {
                                bufferedInputStream2.close();
                            } catch (Exception e3) {
                            }
                        }
                        throw th;
                    }
                }
            } catch (Exception e4) {
            }
        } catch (IOException e5) {
            e = e5;
            bufferedInputStream = null;
        } catch (Throwable th2) {
            th = th2;
            if (bufferedInputStream2 != null) {
            }
            throw th;
        }
        if (bufferedInputStream != null) {
            bufferedInputStream.close();
        }
        return sb.toString();
    }

    public static boolean p(Context context) {
        try {
            NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
            if (activeNetworkInfo != null) {
                return activeNetworkInfo.isConnected();
            }
            return false;
        } catch (Exception e2) {
            return false;
        }
    }

    public static boolean p(String str) {
        boolean z = true;
        try {
            IPackageManager asInterface = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
            try {
                try {
                    if (IPackageManager.class.getMethod("getPackageInfo", String.class, Integer.TYPE, Integer.TYPE).invoke(asInterface, str, 0, 0) == null) {
                        z = false;
                    }
                } catch (IllegalAccessException e2) {
                    e2.printStackTrace();
                    if (IPackageManager.class.getMethod("getPackageInfo", String.class, Integer.TYPE).invoke(asInterface, str, 0) == null) {
                        z = false;
                    }
                } catch (InvocationTargetException e3) {
                    e3.printStackTrace();
                    if (IPackageManager.class.getMethod("getPackageInfo", String.class, Integer.TYPE).invoke(asInterface, str, 0) == null) {
                        z = false;
                    }
                }
            } catch (IllegalArgumentException e4) {
                e4.printStackTrace();
                if (IPackageManager.class.getMethod("getPackageInfo", String.class, Integer.TYPE).invoke(asInterface, str, 0) == null) {
                    z = false;
                }
            } catch (NoSuchMethodException e5) {
                e5.printStackTrace();
                if (IPackageManager.class.getMethod("getPackageInfo", String.class, Integer.TYPE).invoke(asInterface, str, 0) == null) {
                    z = false;
                }
            }
            return z;
        } catch (Throwable th) {
            th.printStackTrace();
            return false;
        }
    }

    private static String[] p(Context context, String str) {
        try {
            PackageInfo packageArchiveInfo = context.getPackageManager().getPackageArchiveInfo(str, 64);
            if (packageArchiveInfo != null && packageArchiveInfo.signatures != null && packageArchiveInfo.signatures.length > 0) {
                return new String[]{e(Arrays.toString(packageArchiveInfo.signatures[0].toByteArray())).toLowerCase(), packageArchiveInfo.applicationInfo.packageName};
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
        return null;
    }

    public static long q(Context context) {
        return com.qihoo.appstore.http.netconfig.g.a(context).e();
    }

    public static int r(Context context) {
        return ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getWidth();
    }

    public static int s(Context context) {
        return ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getHeight();
    }

    public static String t(Context context) {
        return f.d("sava_the_feedback_mail", Config.INVALID_IP);
    }

    public static boolean u(Context context) {
        return f.c("accept_push_app", true);
    }

    public static boolean v(Context context) {
        return f.c("auto_install", true);
    }

    public static boolean w(Context context) {
        return f.c("delete_installed_downfile", true);
    }

    public static void x(Context context) {
        f.b("user_ignore_nw_notification", false);
        f.b("user_activiate_temp_saving", false);
    }

    public static boolean y(Context context) {
        return f.c("perf_key_show_help_new_icon", false);
    }

    public static void z(Context context) {
        if (g == null) {
            g = PreferenceManager.getDefaultSharedPreferences(context);
        }
        com.qihoo360.mobilesafe.util.ag.a(g.edit().putInt("start_count", g.getInt("start_count", 0) + 1));
    }
}