和通讯录 v3.9.6版本的 MD5 值为:669178e2ee1b2311daf378bd20c6bbe1

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


package com.chinamobile.contacts.im.utils;

import android.R;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.Signature;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.StateListDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.hardware.SensorEvent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.v4.app.NotificationCompat;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import com.android.internal.telephony.PhoneConstants;
import com.chinamobile.contacts.im.App;
import com.chinamobile.contacts.im.C0019R;
import com.chinamobile.contacts.im.Main;
import com.chinamobile.contacts.im.config.LoginInfoSP;
import com.chinamobile.contacts.im.data.ContactAccessor;
import com.chinamobile.contacts.im.data.MediaPlatformDBManager;
import com.chinamobile.contacts.im.data.simcard.MultiSimCardAccessor;
import com.chinamobile.contacts.im.jni.Jni;
import com.chinamobile.contacts.im.login.SettingNewLoginMainActivity;
import com.chinamobile.contacts.im.setting.BrowserActivity;
import com.chinamobile.contacts.im.view.HintsDialog;
import com.cmcc.sso.sdk.util.SsoSdkConstants;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.regex.Pattern;

public class ApplicationUtils {
    private static final String ANDROID_CLIENT_ID = "4";
    private static final int BOTTOM_HEIGHT = 56;
    public static final String CONTACTS_SHORTCUT = "contact_shortcut";
    public static final int DEVICE_TYPE_IMEI = 0;
    public static final int DEVICE_TYPE_IMSI = 1;
    public static final int DEVICE_TYPE_MAC = 2;
    public static final String DIAL_SHORTCUT = "dial_shortcut";
    public static final String GAME_SHORTCUT = "game_shortcut";
    public static final String MAIN_SHORTCUT = "main_shortcut";
    public static final String SMS_SHORTCUT = "sms_shortcut";
    public static int SOUND = 0;
    private static final int SPEED_SHRESHOLD = 720;
    private static final String TAG = "ApplicationUtils";
    private static final int UPTATE_INTERVAL_MAX = 500;
    private static final int UPTATE_INTERVAL_TIME = 70;
    public static final float VALUE_ACCELEROMETER_TRIGGER = 19.6f;
    public static HashMap<String, Class> activityHashMap;
    private static String beginString;
    private static Boolean isOPhone = null;
    private static String versionName;

    static {
        activityHashMap = new HashMap<>();
        if (activityHashMap == null) {
            activityHashMap = new HashMap<>();
        }
        activityHashMap.put("SettingNewLoginMainActivity".toLowerCase(), SettingNewLoginMainActivity.class);
        beginString = "icloud37";
    }

    public static boolean isOphone() {
        if (isOPhone == null) {
            if (getMobileManufacturer().contains("OPHONE")) {
                isOPhone = true;
            } else {
                isOPhone = false;
            }
        }
        return isOPhone.booleanValue();
    }

    public static final String getMobileManufacturer() {
        String str = Build.MANUFACTURER;
        return str.toUpperCase().equals("UNKNOWN") ? getMobileModel() : str.toUpperCase();
    }

    public static byte[] bitmap2Bytes(Bitmap bitmap) {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 75, byteArrayOutputStream);
        return byteArrayOutputStream.toByteArray();
    }

    public static boolean isByteArrayEqual(byte[] bArr, byte[] bArr2) {
        if (bArr.length != bArr2.length) {
            return false;
        }
        for (int i = 0; i < bArr.length; i++) {
            if (bArr[i] != bArr2[i]) {
                return false;
            }
        }
        return true;
    }

    public static String getAOIToken(Context context) {
        return context == null ? com.chinamobile.icloud.im.a.b.c.b(App.b()) : com.chinamobile.icloud.im.a.b.c.b(context);
    }

    public static boolean checkNet(Context context) {
        if (isNetworkAvailable(context)) {
            return true;
        }
        HintsDialog hintsDialog = new HintsDialog(context, "温馨提醒", "无法连接网络,请检查网络设置");
        hintsDialog.setButton(new b(context), C0019R.string.setting);
        hintsDialog.setNegtiveButton(new c());
        hintsDialog.show();
        return false;
    }

    private static String getChannelId() {
        String channel = getChannel(App.b());
        if (channel.equals("mcontact_sd_ahkjyxandroid001")) {
            return "2200157492";
        }
        if (channel.equals("mcontact_sd_ahlysjyxandroid001")) {
            return "2200158591";
        }
        if (channel.equals("mcontact_sd_ahhyhdsjyxandroid001")) {
            return "2200158573";
        }
        if (channel.equals("mcontact_sd_ahwtsjyxandroid001")) {
            return "2200158555";
        }
        if (channel.equals("mcontact_sd_ahlxsjyxandroid001")) {
            return "2200158537";
        }
        if (channel.equals("mcontact_sd_sonyandroid001")) {
            return "2200129607";
        }
        if (channel.equals("mcontact_sd_huasengandroid001")) {
            return "2200160733";
        }
        if (channel.equals("mcontact_sd_huaweiandroid001") || channel.equals("mcontact_sd_huaweiandroid002")) {
            return "2200159401";
        }
        if (channel.equals("mcontact_sd_scbaidu001")) {
            return "2200159419";
        }
        return "";
    }

    public static void jumpGameListsView(Context context) {
        if (checkNet(context)) {
            String str = "http://pim.10086.cn/wap/games/mmgamelist.php?token=" + ContactAccessor.getAuth(context).l() + "&endpointId=" + getUUID(context) + "&imis=" + getSubscriberId2(context) + "&channelId=" + getChannelId();
            Intent intent = new Intent(context, (Class<?>) BrowserActivity.class);
            intent.putExtra("url", str);
            intent.putExtra(MediaPlatformDBManager.KEY_TITLE, "游戏推荐");
            context.startActivity(intent);
        }
    }

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

    public static void closeCursor(Cursor cursor) {
        if (cursor != null) {
            try {
                cursor.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static String getUUID(Context context) {
        if (context == null) {
            context = App.b();
        }
        return com.chinamobile.icloud.im.a.b.c.f(context);
    }

    public static String getChannel(Context context) {
        String str;
        Exception e;
        String str2;
        if (context == null) {
            context = App.b();
        }
        String q = com.chinamobile.contacts.im.config.m.q(context);
        if (TextUtils.isEmpty(q)) {
            try {
                str = context.getPackageManager().getApplicationInfo(App.a().getPackageName(), 128).metaData.get("MOBILE_CHANNEL").toString();
            } catch (Exception e2) {
                str = q;
                e = e2;
            }
            try {
                com.chinamobile.contacts.im.config.m.g(context, str);
                str2 = str;
            } catch (Exception e3) {
                e = e3;
                e.printStackTrace();
                str2 = str;
                if (str2 != null) {
                }
            }
            return str2 != null ? "" : str2;
        }
        return q;
    }

    public static boolean isSDAPP() {
        return getChannel(App.b()).startsWith("mcontact_sd_");
    }

    public static int dip2px(Context context, float f) {
        if (context == null) {
            return (int) f;
        }
        return (int) ((context.getResources().getDisplayMetrics().density * f) + 0.5f);
    }

    public static int px2dip(Context context, float f) {
        return (int) ((f / context.getResources().getDisplayMetrics().density) + 0.5f);
    }

    public static boolean isGarbled(String str) {
        char[] charArray = str.toCharArray();
        int i = 0;
        for (char c : charArray) {
            if (c == '?') {
                i++;
            }
        }
        if (i > charArray.length * 0) {
            return true;
        }
        try {
            byte[] bytes = str.getBytes("iso8859-1");
            int i2 = 0;
            int i3 = 0;
            for (byte b2 : bytes) {
                if (b2 == 63) {
                    return false;
                }
                if (b2 >= 0) {
                    i2++;
                } else if (b2 < 0) {
                    i3++;
                }
            }
            if (i2 == bytes.length) {
                return false;
            }
        } catch (UnsupportedEncodingException e) {
            aq.b(TAG, e.getMessage());
        }
        return true;
    }

    public static int phoneWidth(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics);
        return displayMetrics.widthPixels;
    }

    public static String getVersionName(Context context) {
        if (versionName == null) {
            if (context == null) {
                context = App.b();
            }
            try {
                PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
                if (packageInfo != null) {
                    versionName = packageInfo.versionName;
                }
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }
        return versionName;
    }

    public static int getVersionCode(Context context) {
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            if (packageInfo != null) {
                return packageInfo.versionCode;
            }
            return 0;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static void sendNotification(Context context, String str, String str2) {
        com.chinamobile.contacts.im.config.o.e(context, true);
        com.chinamobile.contacts.im.config.o.a(context, str2);
        com.chinamobile.contacts.im.config.o.a(context, 3);
        context.sendBroadcast(new Intent("com.chinamobile.contact.im.SYNC_CLOSE_ACTION"));
        Intent intent = new Intent(context, (Class<?>) Main.class);
        intent.putExtra("tab_action", "TAB_INDEX_SYNC");
        com.chinamobile.contacts.im.manager.d.a(context).i(intent, str2);
    }

    public static void sendAutoSyncCompleteNT(Context context, String str, String str2) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification");
        Intent intent = new Intent();
        intent.setClass(context, Main.class);
        intent.putExtra("tab_action", "SYNC_TAB_LOG");
        PendingIntent activity = PendingIntent.getActivity(context, 0, intent, 134217728);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setContentTitle(str);
        builder.setContentText(str2);
        builder.setWhen(System.currentTimeMillis());
        builder.setAutoCancel(true);
        builder.setContentIntent(activity);
        builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), C0019R.drawable.ic_launcher));
        if (Build.VERSION.SDK_INT >= 21) {
            builder.setSmallIcon(C0019R.drawable.ic_launcher5);
        } else {
            builder.setSmallIcon(C0019R.drawable.ic_launcher);
        }
        notificationManager.notify(20202020, builder.build());
    }

    public static Notification createNotification() {
        Notification notification = new Notification();
        notification.flags = 16;
        return notification;
    }

    public static void cleanNotification(Context context) {
        ((NotificationManager) context.getSystemService("notification")).cancel(19191919);
    }

    public static boolean query_is_register(Context context) {
        return com.chinamobile.icloud.im.a.b.c.c(context);
    }

    public static void doRegister(Context context) {
        try {
            com.chinamobile.icloud.im.a.b.c.a(context, getVersionName(context), getChannel(context));
        } catch (SecurityException e) {
            e.printStackTrace();
        }
    }

    public static String generateString(int i) {
        StringBuffer stringBuffer = new StringBuffer();
        Random random = new Random();
        for (int i2 = 0; i2 < i; i2++) {
            stringBuffer.append(random.nextInt());
        }
        return stringBuffer.toString();
    }

    public static boolean isNetworkAvailable(Context context) {
        NetworkInfo[] allNetworkInfo;
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
        if (connectivityManager == null || (allNetworkInfo = connectivityManager.getAllNetworkInfo()) == null) {
            return false;
        }
        for (NetworkInfo networkInfo : allNetworkInfo) {
            if (networkInfo.getState() == NetworkInfo.State.CONNECTED) {
                return true;
            }
        }
        return false;
    }

    public static boolean isExternalStorageAvailable() {
        return Environment.getExternalStorageState().equals("mounted");
    }

    public static String getMacAddress(Context context) {
        WifiInfo connectionInfo = ((WifiManager) context.getSystemService("wifi")).getConnectionInfo();
        return connectionInfo.getMacAddress() != null ? connectionInfo.getMacAddress() : MultiSimCardAccessor.MODEL_HTCD820U_UNKNOW;
    }

    public static String getPhoneMark(Context context) {
        String deviceId;
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(PhoneConstants.PHONE_KEY);
        if (TextUtils.isEmpty(telephonyManager.getDeviceId())) {
            deviceId = ((WifiManager) context.getSystemService("wifi")).getConnectionInfo().getMacAddress();
        } else {
            deviceId = telephonyManager.getDeviceId();
        }
        return deviceId == null ? "" : deviceId;
    }

    public static String getClientId() {
        return ANDROID_CLIENT_ID;
    }

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

    public static String encrypt(String str, String str2) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance(str);
            messageDigest.update(str2.getBytes());
            byte[] digest = messageDigest.digest();
            StringBuffer stringBuffer = new StringBuffer();
            for (byte b2 : digest) {
                int i = b2 & 255;
                if (i < 16) {
                    stringBuffer.append("0");
                }
                stringBuffer.append(Integer.toHexString(i));
            }
            return stringBuffer.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String getStringOfGarbled(String str, int i) {
        if (isGarbled(str) && i >= 0) {
            try {
                return getStringOfGarbled(new String(str.getBytes("iso8859-1"), "utf-8"), i - 1);
            } catch (UnsupportedEncodingException e) {
                return null;
            }
        }
        return str;
    }

    public static boolean isPhoneNumber(String str) {
        return str.startsWith("147") || Pattern.compile("^1([358])\\d{9}$").matcher(str).matches();
    }

    public static String getUserName(Context context) {
        if (!LoginInfoSP.isLogin(context)) {
            return "";
        }
        return LoginInfoSP.getUserName(context);
    }

    private static boolean isXiaoMi() {
        return Build.BRAND.toLowerCase().contains("xiaomi");
    }

    public static boolean isHuaWei() {
        return Build.MANUFACTURER.toLowerCase().contains(SsoSdkConstants.PHONE_HUAWEI);
    }

    public static void placeCall(Context context, CharSequence charSequence) {
        placeCall(context, charSequence, null);
    }

    public static void placeCall(Context context, CharSequence charSequence, com.chinamobile.contacts.im.call.view.ag agVar) {
        saveCall(context, "" + ((Object) charSequence));
        if (charSequence != null) {
            Uri callUri = getCallUri(charSequence);
            if (charSequence.length() <= 2 && isXiaoMi()) {
                dialNumberForXiaoMi(context, charSequence.toString());
                return;
            }
            if (MultiSimCardAccessor.getInstance().getCurrentSimStatus() == 23 && !Build.MODEL.equals(MultiSimCardAccessor.MODEL_SM_GT_S7562)) {
                new com.chinamobile.contacts.im.call.view.af(context, charSequence.toString(), agVar).show();
                return;
            }
            context.startActivity(new Intent("android.intent.action.CALL", callUri));
            if (agVar != null) {
                agVar.a();
            }
        }
    }

    public static void placeCall(Context context, Uri uri) {
        String replace = uri.toString().replace("tel:", "");
        if (replace.length() <= 2 && isXiaoMi()) {
            dialNumberForXiaoMi(context, replace);
        } else if (MultiSimCardAccessor.getInstance().getCurrentSimStatus() == 23 && !Build.MODEL.equals(MultiSimCardAccessor.MODEL_SM_GT_S7562)) {
            new com.chinamobile.contacts.im.call.view.af(context, uri).show();
        } else {
            context.startActivity(new Intent("android.intent.action.CALL", uri));
        }
    }

    private static void dialNumberForXiaoMi(Context context, String str) {
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.setClassName("com.android.contacts", "com.android.contacts.activities.TwelveKeyDialer");
        intent.setData(Uri.parse("tel:" + str));
        context.startActivity(intent);
    }

    public static boolean isEmergencyNumber(String str) {
        for (String str2 : new String[]{"110", "119", "120", "122"}) {
            if (str.equals(str2)) {
                return true;
            }
        }
        return false;
    }

    public static boolean isCMCCPhone(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        if (str.length() > 11) {
            str = str.substring(str.length() - 11);
        }
        boolean matches = Pattern.compile("^1(3[4-9]|47|5[012789]|8[2378])\\d{8}$").matcher(str).matches();
        if (str.equals("13800138000")) {
            return false;
        }
        return matches;
    }

    public static String getIMEIAndIMSI(Context context) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(PhoneConstants.PHONE_KEY);
        String str = "";
        if (!TextUtils.isEmpty(telephonyManager.getDeviceId())) {
            str = telephonyManager.getDeviceId();
        }
        if (!TextUtils.isEmpty(telephonyManager.getSubscriberId())) {
            return str + "|" + telephonyManager.getSubscriberId();
        }
        return str + "|";
    }

    public static String getDeviceIMEI(Context context) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(PhoneConstants.PHONE_KEY);
        if (TextUtils.isEmpty(telephonyManager.getDeviceId())) {
            return "";
        }
        return telephonyManager.getDeviceId();
    }

    public static String getDeviceIdentifier(Context context, int i) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(PhoneConstants.PHONE_KEY);
        if (i == 0) {
            if (!TextUtils.isEmpty(telephonyManager.getDeviceId())) {
                return telephonyManager.getDeviceId();
            }
        } else if (i == 1) {
            if (!TextUtils.isEmpty(telephonyManager.getSubscriberId())) {
                return telephonyManager.getSubscriberId();
            }
        } else if (i == 2) {
            return getMacAddress(context);
        }
        return "";
    }

    public static PackageInfo getPackageInfo() {
        try {
            return App.a().getPackageManager().getPackageInfo(App.a().getPackageName(), 16384);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String getSubscriberId(Context context) {
        String str;
        try {
            str = ((TelephonyManager) context.getSystemService(PhoneConstants.PHONE_KEY)).getSubscriberId();
        } catch (SecurityException e) {
            e.printStackTrace();
            str = null;
        }
        return !TextUtils.isEmpty(str) ? str : MultiSimCardAccessor.MODEL_HTCD820U_UNKNOW;
    }

    public static String getSubscriberId2(Context context) {
        return ((TelephonyManager) context.getSystemService(PhoneConstants.PHONE_KEY)).getSubscriberId();
    }

    public static StateListDrawable newDrawableSelector(Context context, int i, int i2, int i3, int i4) {
        StateListDrawable stateListDrawable = new StateListDrawable();
        Drawable drawable = i == -1 ? null : context.getResources().getDrawable(i);
        Drawable drawable2 = i2 == -1 ? null : context.getResources().getDrawable(i2);
        Drawable drawable3 = i3 == -1 ? null : context.getResources().getDrawable(i3);
        Drawable drawable4 = i4 != -1 ? context.getResources().getDrawable(i4) : null;
        stateListDrawable.addState(new int[]{R.attr.state_pressed}, drawable2);
        stateListDrawable.addState(new int[]{R.attr.state_focused}, drawable3);
        stateListDrawable.addState(new int[]{R.attr.state_selected}, drawable4);
        stateListDrawable.addState(new int[0], drawable);
        return stateListDrawable;
    }

    public static boolean IfaddShortCut(Context context, String str) {
        String str2;
        boolean z;
        if (!Build.MODEL.equals("GT-N7100") && !Build.MODEL.equals("GT-N7100")) {
            ContentResolver contentResolver = context.getContentResolver();
            aq.a("IfaddShortCut", "getSystemVersion():" + getSystemVersion() + "--------------");
            aq.a("IfaddShortCut", "getSystemVersion():" + getSystemVersion() + "-------------- getMobileModel=" + getMobileModel());
            if (getSystemVersion() < 8) {
                str2 = "content://com.android.launcher.settings/favorites?notify=true";
            } else if (getSystemVersion() == 14) {
                str2 = "content://com.android.launcher2.settings/favorites?notify=true";
            } else if (getSystemVersion() == 15 || getSystemVersion() == 16) {
                if (getMobileManufacturer().contains("SAMSUNG")) {
                    str2 = "content://com.sec.android.app.launcher.settings/favorites?notify=true";
                    if ("GT-I9100".equals(getMobileModel())) {
                        str2 = "content://com.sec.android.app.twlauncher.settings/favorites?notify=true";
                    }
                } else if (getMobileModel().contains("HTC")) {
                    str2 = "content://com.htc.launcher.settings/favorites?notify=true";
                } else if (getMobileManufacturer().contains("ZTE")) {
                    str2 = "content://com.android.launcher2.settings/favorites?notify=true";
                } else if (getMobileManufacturer().contains(MultiSimCardAccessor.MODEL_HUAWEI_SUR_TL00)) {
                    str2 = "content://com.huawei.launcher2.settings/favorites?notify=true";
                } else {
                    str2 = "content://com.android.launcher.settings/favorites?notify=true";
                }
            } else if (getMobileManufacturer().contains("SAMSUNG")) {
                str2 = "content://com.sec.android.app.twlauncher.settings/favorites?notify=true";
            } else if (getMobileManufacturer().contains("HTC")) {
                str2 = "content://com.htc.launcher.settings/favorites?notify=true";
            } else if (getMobileManufacturer().contains("MOT") && getMobileModel().contains("MT870")) {
                str2 = "content://com.android.launcher.settings/favorites?notify=true";
            } else if (MultiSimCardAccessor.MODEL_OPPO_QCOM_1107.equals(Build.MODEL) || "R8107".equals(Build.MODEL)) {
                str2 = "content://com.oppo.launcher.settings/singledesktopitems?notify=true";
            } else if (Build.MODEL.contains("TCL")) {
                str2 = "content://com.lewa.launcher.settings/favorites?notify=true";
            } else {
                str2 = "content://com.android.launcher2.settings/favorites?notify=true";
            }
            aq.a("应用名称", str);
            Cursor query = contentResolver.query(Uri.parse(str2), new String[]{MediaPlatformDBManager.KEY_TITLE, "iconResource"}, "title=? and iconPackage=?", new String[]{str.trim(), context.getPackageName()}, null);
            if (query != null && query.getCount() > 0) {
                aq.a("快捷方式", "已创建");
                z = true;
            } else {
                aq.a("快捷方式", "未创建");
                z = false;
            }
            if (query != null) {
                closeCursor(query);
                return z;
            }
            return z;
        }
        return false;
    }

    public static boolean addShortcut2(Context context, String str, String str2, int i, String str3) {
        String str4;
        Context context2 = null;
        PackageManager packageManager = context.getPackageManager();
        Intent intent = new Intent("android.intent.action.MAIN", (Uri) null);
        intent.addCategory("android.intent.category.LAUNCHER");
        List<ResolveInfo> queryIntentActivities = packageManager.queryIntentActivities(intent, 1);
        int i2 = 0;
        while (true) {
            if (i2 >= queryIntentActivities.size()) {
                i = 0;
                str4 = null;
                str2 = MultiSimCardAccessor.MODEL_HTCD820U_UNKNOW;
                break;
            }
            if (!queryIntentActivities.get(i2).activityInfo.packageName.equals(str)) {
                i2++;
            } else {
                str4 = "com.chinamobile.contacts.im.Main";
                break;
            }
        }
        Intent intent2 = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
        intent2.putExtra("android.intent.extra.shortcut.NAME", str2);
        intent2.putExtra("duplicate", false);
        new ComponentName(str, str4);
        Intent intent3 = new Intent();
        if (str3.equals(SMS_SHORTCUT)) {
            intent3.setAction("android.intent.action.MAIN").setComponent(new ComponentName(str, "com.chinamobile.contacts.im.MmsActivity")).setType(str3);
        } else if (str3.equals(DIAL_SHORTCUT)) {
            intent3.setAction("android.intent.action.MAIN").setComponent(new ComponentName(str, "com.chinamobile.contacts.im.DialActivity")).setType(str3);
        } else if (str3.equals(MAIN_SHORTCUT)) {
            intent3.setAction("android.intent.action.MAIN").setComponent(new ComponentName(str, "com.chinamobile.contacts.im.Main")).setType(str3);
        } else {
            intent3.setAction("android.intent.action.MAIN").setComponent(new ComponentName(str, "com.chinamobile.contacts.im.ContactActivity")).setType(str3);
        }
        intent2.putExtra("android.intent.extra.shortcut.INTENT", intent3);
        if (context.getPackageName().equals(str)) {
            context2 = context;
        } else {
            try {
                context2 = context.createPackageContext(str, 3);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }
        if (context2 != null) {
            intent2.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(context2, i));
        }
        context.sendBroadcast(intent2);
        return true;
    }

    public static boolean addShortcut(Context context, String str, String str2, int i, String str3) {
        String str4;
        Context context2 = null;
        if (IfaddShortCut(context, str2)) {
            return false;
        }
        PackageManager packageManager = context.getPackageManager();
        Intent intent = new Intent("android.intent.action.MAIN", (Uri) null);
        intent.addCategory("android.intent.category.LAUNCHER");
        List<ResolveInfo> queryIntentActivities = packageManager.queryIntentActivities(intent, 1);
        int i2 = 0;
        while (true) {
            if (i2 >= queryIntentActivities.size()) {
                i = 0;
                str4 = null;
                str2 = MultiSimCardAccessor.MODEL_HTCD820U_UNKNOW;
                break;
            }
            if (!queryIntentActivities.get(i2).activityInfo.packageName.equals(str)) {
                i2++;
            } else {
                str4 = "com.chinamobile.contacts.im.Main";
                break;
            }
        }
        Intent intent2 = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
        intent2.putExtra("android.intent.extra.shortcut.NAME", str2);
        intent2.putExtra("duplicate", false);
        new ComponentName(str, str4);
        Intent intent3 = new Intent();
        if (str3.equals(SMS_SHORTCUT)) {
            intent3.setAction("android.intent.action.MAIN").setComponent(new ComponentName(str, "com.chinamobile.contacts.im.MmsActivity")).setType(str3);
        } else if (str3.equals(DIAL_SHORTCUT)) {
            intent3.setAction("android.intent.action.MAIN").setComponent(new ComponentName(str, "com.chinamobile.contacts.im.DialActivity")).setType(str3);
        } else if (str3.equals(MAIN_SHORTCUT)) {
            intent3.setAction("android.intent.action.MAIN").setComponent(new ComponentName(str, "com.chinamobile.contacts.im.Main")).setType(str3);
        } else {
            intent3.setAction("android.intent.action.MAIN").setComponent(new ComponentName(str, "com.chinamobile.contacts.im.ContactActivity")).setType(str3);
        }
        intent2.putExtra("android.intent.extra.shortcut.INTENT", intent3);
        if (context.getPackageName().equals(str)) {
            context2 = context;
        } else {
            try {
                context2 = context.createPackageContext(str, 3);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }
        if (context2 != null) {
            intent2.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(context2, i));
        }
        PreferenceManager.getDefaultSharedPreferences(context);
        context.sendBroadcast(intent2);
        return true;
    }

    public static void delShortcut(Context context) {
        Intent intent = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
        intent.putExtra("android.intent.extra.shortcut.NAME", "和通讯录");
        ComponentName componentName = new ComponentName("com.chinamobile.contacts.im", "com.chinamobile.contacts.im.Main");
        Intent intent2 = new Intent();
        intent2.setAction("android.intent.action.MAIN").addFlags(270532608).setComponent(componentName).addCategory("android.intent.category.LAUNCHER");
        intent.putExtra("android.intent.extra.shortcut.INTENT", intent2);
        context.sendBroadcast(intent);
        Intent intent3 = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
        intent3.putExtra("android.intent.extra.shortcut.NAME", "拨号");
        ComponentName componentName2 = new ComponentName("com.chinamobile.contacts.im", "com.chinamobile.contacts.im.Main");
        Intent intent4 = new Intent();
        intent4.setAction("android.intent.action.MAIN").setComponent(componentName2);
        intent3.putExtra("android.intent.extra.shortcut.INTENT", intent4);
        context.sendBroadcast(intent3);
        Intent intent5 = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
        intent5.putExtra("android.intent.extra.shortcut.NAME", "信息");
        ComponentName componentName3 = new ComponentName("com.chinamobile.contacts.im", "com.chinamobile.contacts.im.Main");
        Intent intent6 = new Intent();
        intent6.setAction("android.intent.action.MAIN").setComponent(componentName3);
        intent5.putExtra("android.intent.extra.shortcut.INTENT", intent6);
        context.sendBroadcast(intent5);
        Intent intent7 = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
        intent3.putExtra("android.intent.extra.shortcut.NAME", "和多号");
        ComponentName componentName4 = new ComponentName("com.chinamobile.contacts.im", "com.chinamobile.contacts.im.Main");
        Intent intent8 = new Intent();
        intent8.setAction("android.intent.action.MAIN").setComponent(componentName4);
        intent7.putExtra("android.intent.extra.shortcut.INTENT", intent8);
        context.sendBroadcast(intent7);
    }

    public static void startActivityForResult(Context context, String str, Intent intent, int i) {
        Intent intent2 = getIntent(context, str, intent);
        if (intent2 != null) {
            if (context instanceof Activity) {
                ((Activity) context).startActivityForResult(intent2, i);
            } else {
                context.startActivity(intent2);
            }
        }
    }

    private static Intent getIntent(Context context, String str, Intent intent) {
        Intent intent2 = null;
        Class cls = activityHashMap.get(str.toLowerCase());
        if (cls != null) {
            if (intent != null) {
                intent2 = new Intent(intent);
            } else {
                intent2 = new Intent();
            }
            intent2.setClass(context, cls);
        } else {
            aq.a("Activity", "can't find activity named:" + str);
        }
        return intent2;
    }

    public static Bitmap getCroppedBitmap(Bitmap bitmap, boolean z) {
        if (bitmap == null) {
            return null;
        }
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int min = Math.min(width, height);
        int abs = Math.abs(width - height) / 2;
        if (width > height) {
            bitmap = Bitmap.createBitmap(bitmap, abs, 0, min, min);
        } else if (width < height) {
            bitmap = Bitmap.createBitmap(bitmap, 0, abs, min, min);
        }
        Bitmap createBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        Canvas canvas = new Canvas(createBitmap);
        BitmapShader bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
        shapeDrawable.getPaint().setShader(bitmapShader);
        shapeDrawable.setBounds(1, 1, min - 1, min - 1);
        shapeDrawable.draw(canvas);
        if (!z) {
            Bitmap createScaledBitmap = Bitmap.createScaledBitmap(((BitmapDrawable) App.b().getResources().getDrawable(C0019R.drawable.icon_border)).getBitmap(), min, min, true);
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            canvas.drawBitmap(createScaledBitmap, rect, rect, paint);
            if (createScaledBitmap != createBitmap) {
                createScaledBitmap.recycle();
            }
        }
        if (bitmap != createBitmap) {
            bitmap.recycle();
        }
        return createBitmap;
    }

    public static Bitmap getCroppedCloudBitmap(Bitmap bitmap) {
        if (bitmap == null) {
            return null;
        }
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int min = Math.min(width, height);
        int abs = Math.abs(width - height) / 2;
        if (width > height) {
            bitmap = Bitmap.createBitmap(bitmap, abs, 0, min, min);
        } else if (width < height) {
            bitmap = Bitmap.createBitmap(bitmap, 0, abs, min, min);
        }
        Bitmap createBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(createBitmap);
        BitmapShader bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
        shapeDrawable.getPaint().setShader(bitmapShader);
        shapeDrawable.setBounds(1, 1, min - 1, min - 1);
        shapeDrawable.draw(canvas);
        return createBitmap;
    }

    public static boolean isRealPhoneNumber(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        String a2 = bb.a(str, true);
        return !TextUtils.isEmpty(a2) && a2.length() == 11 && a2.startsWith("1");
    }

    public static boolean isUserPhoneBunded(Context context) {
        String userName = LoginInfoSP.getUserName(context);
        if (!TextUtils.isEmpty(userName) && userName.length() == 11 && userName.startsWith("1")) {
            return true;
        }
        return LoginInfoSP.isBunding(context);
    }

    public static String getBundedPhoneNumber(Context context) {
        String str = "";
        if (LoginInfoSP.isBunding(context)) {
            str = LoginInfoSP.getMobile(context);
        }
        if (TextUtils.isEmpty(str) || str.length() != 11 || !str.startsWith("1")) {
            String userName = LoginInfoSP.getUserName(context);
            return (!TextUtils.isEmpty(userName) && userName.length() == 11 && userName.startsWith("1")) ? userName : str;
        }
        return str;
    }

    public static Uri getCallUri(CharSequence charSequence) {
        return Uri.parse("tel:" + charSequence.toString().replaceAll("#", Uri.encode("#")));
    }

    public static boolean isAct(Context context) {
        String format = new SimpleDateFormat("yyyy-MM-dd").format((Date) new java.sql.Date(System.currentTimeMillis()));
        int compareTo = com.chinamobile.contacts.im.config.m.t(context).compareTo(format);
        String u = com.chinamobile.contacts.im.config.m.u(context);
        int lastIndexOf = u.lastIndexOf("&");
        boolean z = lastIndexOf > 0 && u.substring(lastIndexOf + 1).startsWith(format);
        if (compareTo >= 0 || !z || !LoginInfoSP.isLogin(context) || !LoginInfoSP.isBunding(context) || !isCMCCPhone(LoginInfoSP.getItem(context))) {
            return false;
        }
        com.chinamobile.contacts.im.config.m.h(context, format);
        return true;
    }

    public static void saveCall(Context context, String str) {
        com.chinamobile.contacts.im.share.a.f3426a = true;
        long currentTimeMillis = System.currentTimeMillis();
        if (com.chinamobile.contacts.im.config.m.t(context).compareTo(new SimpleDateFormat("yyyy-MM-dd").format((Date) new java.sql.Date(currentTimeMillis))) < 0 && LoginInfoSP.isLogin(context) && LoginInfoSP.isBunding(context)) {
            String item = LoginInfoSP.getItem(context);
            if (isCMCCPhone(item)) {
                com.chinamobile.contacts.im.config.m.i(context, item + "&" + str + "&" + new SimpleDateFormat("yyyy-MM-dd-HH-mm").format((Date) new java.sql.Date(currentTimeMillis)));
            }
        }
    }

    public static void updateConfig(Context context) {
        Configuration configuration;
        boolean z = false;
        SOUND = Settings.System.getInt(context.getContentResolver(), "sound_effects_enabled", 0);
        Resources resources = context.getResources();
        if (resources != null && (configuration = resources.getConfiguration()) != null) {
            boolean z2 = Build.VERSION.SDK != null && Integer.parseInt(Build.VERSION.SDK) >= 14;
            if (z2) {
                Configuration configuration2 = new Configuration();
                configuration2.setToDefaults();
                if (Float.compare(configuration.fontScale, configuration2.fontScale) != 0) {
                    if (com.chinamobile.contacts.im.config.h.h) {
                        configuration.fontScale = configuration2.fontScale;
                        z = z2;
                    } else {
                        configuration.fontScale = 1.0f;
                    }
                }
                if (configuration.orientation != 1) {
                    configuration.orientation = 1;
                    z = true;
                }
                if (!z) {
                    resources.updateConfiguration(configuration, resources.getDisplayMetrics());
                    return;
                }
                return;
            }
            z = z2;
            if (configuration.orientation != 1) {
            }
            if (!z) {
            }
        }
    }

    public static boolean isEmailNumber(String str) {
        return !TextUtils.isEmpty(str) && str.contains("@");
    }

    public static ArrayList<String> getHomePackages(Context context) {
        ArrayList<String> arrayList = new ArrayList<>();
        PackageManager packageManager = context.getPackageManager();
        Intent intent = new Intent("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.HOME");
        Iterator<ResolveInfo> it = packageManager.queryIntentActivities(intent, 65536).iterator();
        while (it.hasNext()) {
            arrayList.add(it.next().activityInfo.packageName);
        }
        return arrayList;
    }

    public static boolean isSystemHome(Context context) {
        String packageName = ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1).get(0).topActivity.getPackageName();
        ArrayList<String> homePackages = getHomePackages(context);
        if (packageName.contains("incallui")) {
            return true;
        }
        return homePackages.contains(packageName);
    }

    public static void printDisplayMetrics(Activity activity) {
        Display defaultDisplay = activity.getWindowManager().getDefaultDisplay();
        aq.d("king", "mDisplay.getWidth() " + defaultDisplay.getWidth() + " getHeight " + defaultDisplay.getHeight());
    }

    public static String encodeValue(String str) {
        Exception e;
        String str2;
        try {
            str2 = !TextUtils.isEmpty(str) ? beginString + com.chinamobile.icloud.im.sync.c.a.b(t.a(str.getBytes(), Jni.getBaseInfo()), 2) : str;
            try {
                aq.b(TAG, "encodeValue url:" + str);
                aq.b(TAG, "encodeValue value:" + str2);
            } catch (Exception e2) {
                e = e2;
                e.printStackTrace();
                aq.a(TAG, "encodeValue:" + e.toString());
                return str2;
            }
        } catch (Exception e3) {
            e = e3;
            str2 = str;
        }
        return str2;
    }

    public static String decodeValue(String str) {
        String str2;
        try {
            if (!TextUtils.isEmpty(str)) {
                if (str.startsWith(beginString)) {
                    String substring = str.substring(beginString.length());
                    try {
                        str2 = new String(t.b(com.chinamobile.icloud.im.sync.c.a.a(substring, 2), Jni.getBaseInfo()));
                    } catch (Exception e) {
                        e = e;
                        str = substring;
                        e.printStackTrace();
                        aq.a(TAG, "decodeValue:" + e.toString());
                        return str;
                    }
                } else {
                    str2 = str;
                }
                try {
                    aq.b(TAG, "decodeValue url:" + str);
                    aq.b(TAG, "decodeValue value:" + str2);
                    return str2;
                } catch (Exception e2) {
                    str = str2;
                    e = e2;
                    e.printStackTrace();
                    aq.a(TAG, "decodeValue:" + e.toString());
                    return str;
                }
            }
            return str;
        } catch (Exception e3) {
            e = e3;
        }
    }

    public static String getSignInfo(Context context) {
        try {
            Signature signature = context.getPackageManager().getPackageInfo(context.getPackageName(), 64).signatures[0];
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(signature.toByteArray());
            return toHexString(messageDigest.digest());
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return null;
        } catch (NoSuchAlgorithmException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    private static String toHexString(byte[] bArr) {
        StringBuffer stringBuffer = new StringBuffer();
        int length = bArr.length;
        for (int i = 0; i < length; i++) {
            byte2hex(bArr[i], stringBuffer);
            if (i < length - 1) {
                stringBuffer.append(":");
            }
        }
        return stringBuffer.toString();
    }

    private static void byte2hex(byte b2, StringBuffer stringBuffer) {
        char[] cArr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
        stringBuffer.append(cArr[(b2 & 240) >> 4]);
        stringBuffer.append(cArr[b2 & 15]);
    }

    public static void shareToFriends(Context context, String str) {
        Intent intent = new Intent("android.intent.action.SEND");
        intent.setType("text/plain");
        intent.putExtra("android.intent.extra.TEXT", str);
        context.startActivity(Intent.createChooser(intent, "选择分享"));
    }

    public static String int2ip(int i) {
        StringBuilder sb = new StringBuilder();
        sb.append(i & 255).append(".");
        sb.append((i >> 8) & 255).append(".");
        sb.append((i >> 16) & 255).append(".");
        sb.append((i >> 24) & 255);
        return sb.toString();
    }

    public static String getLocalIpAddress(Context context) {
        try {
            return int2ip(((WifiManager) context.getSystemService("wifi")).getConnectionInfo().getIpAddress());
        } catch (Exception e) {
            return " 获取IP出错鸟!!!!请保证是WIFI,或者请重新打开网络!\n" + e.getMessage();
        }
    }

    public static boolean debug() {
        return "Y".equalsIgnoreCase(App.b().getString(C0019R.string.IS_DEBUG));
    }

    public static boolean isNeedShake(SensorEvent sensorEvent, be beVar) {
        long currentTimeMillis;
        long j;
        try {
            currentTimeMillis = System.currentTimeMillis();
            j = currentTimeMillis - beVar.g;
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (j < 70 || beVar.g <= 0 || j > 500) {
            if (beVar.g <= 0 || j > 500) {
                beVar.a();
                beVar.g = currentTimeMillis;
            }
            return false;
        }
        beVar.g = currentTimeMillis;
        float f = sensorEvent.values[0];
        float f2 = sensorEvent.values[1];
        float f3 = sensorEvent.values[2];
        float f4 = f - beVar.f3717a;
        float f5 = f2 - beVar.f3718b;
        float f6 = f3 - beVar.c;
        beVar.f3717a = f;
        beVar.f3718b = f2;
        beVar.c = f3;
        double sqrt = 10000.0d * (Math.sqrt(((f4 * f4) + (f5 * f5)) + (f6 * f6)) / j);
        if (sqrt >= 720.0d) {
            if (currentTimeMillis - beVar.h > 500) {
                beVar.i = 0;
            }
            int i = 0;
            if (beVar.d * f4 < 0.0f) {
                i = 1;
            }
            if (beVar.e * f5 < 0.0f) {
                i++;
            }
            if (beVar.f * f6 < 0.0f) {
                i++;
            }
            if (i > 0) {
                beVar.i++;
            }
            beVar.h = currentTimeMillis;
        }
        beVar.d = f4;
        beVar.e = f5;
        beVar.f = f6;
        if (beVar.i > 2) {
            beVar.a();
            return true;
        }
        if (sqrt < 720.0d) {
            beVar.a();
        }
        return false;
    }

    public static View createBottomIgnoredView(Activity activity) {
        View view = new View(activity);
        DisplayMetrics displayMetrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        int i = displayMetrics.widthPixels;
        int i2 = displayMetrics.heightPixels;
        view.setTop(i2 - dip2px(activity, 56.0f));
        view.setLeft(0);
        view.setBottom(i2);
        view.setRight(i);
        return view;
    }

    public static View createIgnoredView(Activity activity) {
        View view = new View(activity);
        DisplayMetrics displayMetrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        int i = displayMetrics.widthPixels;
        int i2 = displayMetrics.heightPixels;
        view.setTop(0);
        view.setLeft(0);
        view.setBottom(i2 - dip2px(activity, 56.0f));
        view.setRight(i);
        return view;
    }

    public static boolean isWifiConnected(Context context) {
        return ((ConnectivityManager) context.getSystemService("connectivity")).getNetworkInfo(1).isConnected();
    }
}