diff --git a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/build.gradle b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/build.gradle index fc77bc40..7da43977 100644 --- a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/build.gradle +++ b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' -version = "1.6.21" +version = "1.6.22" android { compileSdkVersion 21 diff --git a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/android/sdk/SensorsDataAPI.java b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/android/sdk/SensorsDataAPI.java index 52d8fb36..1fd4ff9b 100644 --- a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/android/sdk/SensorsDataAPI.java +++ b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/android/sdk/SensorsDataAPI.java @@ -110,6 +110,24 @@ String getProfileName() { final String packageName = context.getApplicationContext().getPackageName(); + { + //中国移动 + sCarrierMap.put("46000", " 中国移动"); + sCarrierMap.put("46002", " 中国移动"); + sCarrierMap.put("46007", " 中国移动"); + sCarrierMap.put("46008", " 中国移动"); + + //中国联通 + sCarrierMap.put("46001", " 中国联通"); + sCarrierMap.put("46006", " 中国联通"); + sCarrierMap.put("46009", " 中国联通"); + + //中国电信 + sCarrierMap.put("46003", " 中国电信"); + sCarrierMap.put("46005", " 中国电信"); + sCarrierMap.put("46011", " 中国电信"); + } + try { final ApplicationInfo appInfo = context.getApplicationContext().getPackageManager() .getApplicationInfo(packageName, PackageManager.GET_META_DATA); @@ -211,16 +229,12 @@ String getProfileName() { .TELEPHONY_SERVICE); String operatorString = telephonyManager.getSimOperator(); - if (operatorString == null) { - // DO NOTHING - } else if (operatorString.equals("46000") || operatorString.equals("46002")) { - deviceInfo.put("$carrier", "中国移动"); - } else if (operatorString.equals("46001")) { - deviceInfo.put("$carrier", "中国联通"); - } else if (operatorString.equals("46003")) { - deviceInfo.put("$carrier", "中国电信"); - } else { - deviceInfo.put("$carrier", "其他"); + if (!TextUtils.isEmpty(operatorString)) { + if (sCarrierMap.containsKey(operatorString)) { + deviceInfo.put("$carrier", sCarrierMap.get(operatorString)); + } else { + deviceInfo.put("$carrier", "其他"); + } } } @@ -1404,7 +1418,7 @@ private static void mergeJSONObject(final JSONObject source, JSONObject dest) static final int VTRACK_SUPPORTED_MIN_API = 16; // SDK版本 - static final String VERSION = "1.6.21"; + static final String VERSION = "1.6.22"; static Boolean ENABLE_LOG = false; @@ -1415,6 +1429,7 @@ private static void mergeJSONObject(final JSONObject source, JSONObject dest) // Maps each token to a singleton SensorsDataAPI instance private static final Map sInstanceMap = new HashMap(); private static final SharedPreferencesLoader sPrefsLoader = new SharedPreferencesLoader(); + private static final Map sCarrierMap = new HashMap<>(); // Configures /* SensorsAnalytics 地址 */ diff --git a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/android/sdk/SystemInformation.java b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/android/sdk/SystemInformation.java index eb06e519..dd8f80b3 100644 --- a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/android/sdk/SystemInformation.java +++ b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/android/sdk/SystemInformation.java @@ -105,8 +105,12 @@ public Boolean isWifiConnected() { .checkCallingOrSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE)) { ConnectivityManager connManager = (ConnectivityManager) this.mContext.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo wifiInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - ret = wifiInfo.isConnected(); + if (connManager != null) { + NetworkInfo wifiInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); + if (wifiInfo != null) { + ret = wifiInfo.isConnected(); + } + } } return ret; diff --git a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/android/sdk/util/SensorsDataUtils.java b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/android/sdk/util/SensorsDataUtils.java index db06b483..61d5e213 100644 --- a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/android/sdk/util/SensorsDataUtils.java +++ b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/src/main/java/com/sensorsdata/analytics/android/sdk/util/SensorsDataUtils.java @@ -60,8 +60,11 @@ public static String networkType(Context context) { // Wifi ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - if (manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting()) { - return "WIFI"; + if (manager != null) { + NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); + if (networkInfo != null && networkInfo.isConnectedOrConnecting()) { + return "WIFI"; + } } // Mobile network