柬埔寨通 v6.1.5版本的 MD5 值为:9b68581ac30883219d6a25858a099d6b
以下内容为反编译后的 UaidTracker.java 源代码,内容仅作参考
package com.nirvana.tools.logger;
import android.content.Context;
import android.net.Network;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import com.nirvana.tools.cache.CacheHandler;
import com.nirvana.tools.cache.CacheManager;
import com.nirvana.tools.cache.SharedPreferenceTemplate;
import com.nirvana.tools.core.ExecutorManager;
import com.nirvana.tools.core.MobileNetRequestManager;
import com.nirvana.tools.core.NetworkUtils;
import com.nirvana.tools.core.SupportJarUtils;
import com.nirvana.tools.logger.uaid.HttpUtils;
import com.nirvana.tools.logger.uaid.UaidUtils;
import com.taobao.agoo.a.a.b;
import java.text.ParseException;
import org.json.JSONException;
import org.json.JSONObject;
public class UaidTracker {
private static final String CMCC = "CMCC";
private static final long CMCC_EXPIRED_TIME = 120000;
private static final String CMCC_URL = "https://verify.cmpassport.com/h5/getMobile";
private static final String CUCC = "CUCC";
private static final long CUCC_EXPIRED_TIME = 60000;
private static final String CUCC_GET_AUTH_ADDR_URL = "https://nisportal.10010.com:9001/api";
private static final String KEY_CACHE_UAID_TRACKER = "KEY_CACHE_UAID_TRACKER";
private static final String TAG = "UaidTracker";
private static final String UAID_EXPIRED_TIME_KEY = "expiredTime";
private static final String UAID_ISUSABLE_KEY = "isUsable";
private static final String UAID_TOKENS_KEY = "tokens";
private static final String UAID_TRACKER_DATA = "UAID_TRACKER_DATA";
private static final int UAID_TRACKER_DATA_VERSION = 1;
private static boolean isTackerEnable = false;
private static volatile UaidTracker sInstance;
private boolean isLoggerEnable = false;
private String cmccAppID = "";
private String cmccAppKey = "";
private String cuccAppID = "";
private CacheHandler getCacheHandler(Context context, String str, String str2) {
CacheManager cacheManager = CacheManager.getInstance(context.getApplicationContext());
CacheHandler cacheHandler = cacheManager.getCacheHandler(KEY_CACHE_UAID_TRACKER);
if (cacheHandler != null) {
return cacheHandler;
}
return cacheManager.registerCacheHandler(KEY_CACHE_UAID_TRACKER, (String) new SharedPreferenceTemplate(1, false, UAID_TRACKER_DATA, str2 + str));
}
public static UaidTracker getInstance() {
if (sInstance == null) {
synchronized (UaidTracker.class) {
if (sInstance == null) {
sInstance = new UaidTracker();
}
}
}
return sInstance;
}
public static boolean isEnable() {
return isTackerEnable;
}
public void requestToken(Context context, String str, String str2, boolean z, Network network) {
if ("CMCC".equals(str)) {
requestTokenCmcc(context, str, str2, z, network);
} else if ("CUCC".equals(str)) {
requestTokenCucc(context, str, str2, z, network);
}
}
private void requestTokenCmcc(Context context, String str, String str2, boolean z, Network network) {
if (z ? new MobileNetRequestManager().switchToMobile_4x(context, CMCC_URL) : true) {
try {
String post = HttpUtils.post(CMCC_URL, UaidUtils.composeCmccGetTokenParams(this.cmccAppID, this.cmccAppKey), 3000, network);
if (this.isLoggerEnable) {
Log.w(TAG, "requestTokenCmcc====respone:" + post);
}
JSONObject jSONObject = new JSONObject(post);
JSONObject jSONObject2 = jSONObject.getJSONObject("body");
JSONObject jSONObject3 = jSONObject.getJSONObject("header");
String string = jSONObject2.getString(b.JSON_ERRORCODE);
String string2 = jSONObject2.getString("token");
String string3 = jSONObject3.getString("timestamp");
if (!"103000".equals(string) || TextUtils.isEmpty(string2)) {
return;
}
JSONObject jSONObject4 = new JSONObject();
JSONObject jSONObject5 = new JSONObject();
jSONObject5.put("token", string2);
jSONObject4.put(UAID_TOKENS_KEY, jSONObject5);
Long valueOf = Long.valueOf(System.currentTimeMillis());
if (!TextUtils.isEmpty(string3)) {
try {
valueOf = Long.valueOf(UaidUtils.TIMESTAMP_FORMAT.parse(string3).getTime());
} catch (ParseException e) {
e.printStackTrace();
}
}
jSONObject4.put(UAID_EXPIRED_TIME_KEY, valueOf.longValue() + CMCC_EXPIRED_TIME);
jSONObject4.put(UAID_ISUSABLE_KEY, false);
getCacheHandler(context, str, str2).save(jSONObject4.toString());
} catch (JSONException e2) {
e2.printStackTrace();
if (this.isLoggerEnable) {
Log.e(TAG, "requestTokenCmcc====e:" + e2.getMessage());
}
}
}
}
private void requestTokenCucc(Context context, String str, String str2, boolean z, Network network) {
String string;
boolean switchToMobile_4x = z ? new MobileNetRequestManager().switchToMobile_4x(context, CUCC_GET_AUTH_ADDR_URL) : true;
if (!switchToMobile_4x) {
return;
}
String str3 = HttpUtils.get("https://nisportal.10010.com:9001/api?" + UaidUtils.composeCuccAuthAddrParams(this.cuccAppID), 3000, network);
if (this.isLoggerEnable) {
Log.w(TAG, "requestTokenCucc==url==response:" + str3);
}
if (!TextUtils.isEmpty(str3)) {
try {
string = new JSONObject(str3).getString("authurl");
} catch (JSONException e) {
e.printStackTrace();
}
if (TextUtils.isEmpty(string)) {
if (z) {
switchToMobile_4x = new MobileNetRequestManager().switchToMobile_4x(context, string);
}
if (switchToMobile_4x) {
String str4 = HttpUtils.get(string + "/api?" + UaidUtils.composeCuccAuthCodeParams(this.cuccAppID, NetworkUtils.getLocalIPAddress()), 3000, network);
if (this.isLoggerEnable) {
Log.w(TAG, "requestTokenCucc==token==response:" + str4);
}
try {
JSONObject jSONObject = new JSONObject(str4);
if (jSONObject.has("code")) {
JSONObject jSONObject2 = new JSONObject();
jSONObject2.put(UAID_TOKENS_KEY, jSONObject);
jSONObject2.put(UAID_EXPIRED_TIME_KEY, Long.valueOf(System.currentTimeMillis()).longValue() + 60000);
jSONObject2.put(UAID_ISUSABLE_KEY, false);
getCacheHandler(context, str, str2).save(jSONObject2.toString());
return;
}
return;
} catch (JSONException e2) {
if (this.isLoggerEnable) {
Log.e(TAG, "requestTokenCucc====e:" + e2.getMessage());
return;
}
return;
}
}
return;
}
return;
}
string = "";
if (TextUtils.isEmpty(string)) {
}
}
private void switchToMobileNet(final Context context, final String str, final String str2) {
ExecutorManager.getInstance().scheduleFuture(new ExecutorManager.SafeRunnable() {
@Override
protected void onException(Throwable th) {
if (UaidTracker.this.isLoggerEnable) {
Log.e(UaidTracker.TAG, "====safeRun===Failed:" + th.getMessage());
}
}
@Override
protected void safeRun() {
if (NetworkUtils.isMobileNetConnected(context)) {
Log.i(UaidTracker.TAG, "====isMobileNetConnected===");
UaidTracker.this.requestToken(context, str, str2, false, null);
return;
}
if (NetworkUtils.isMobileNetworkOpen(context)) {
Log.i(UaidTracker.TAG, "====isMobileNetworkOpen===");
int checkSelfPermission = SupportJarUtils.checkSelfPermission(context.getApplicationContext(), "android.permission.CHANGE_NETWORK_STATE");
int checkSelfPermission2 = SupportJarUtils.checkSelfPermission(context.getApplicationContext(), "android.permission.WRITE_SETTINGS");
if (checkSelfPermission != 0) {
Log.w(UaidTracker.TAG, "====permissionChangeNet==NotGrant===");
return;
}
if (checkSelfPermission2 != 0) {
Log.w(UaidTracker.TAG, "====permissionWriteSet==NotGrant===");
}
if (Build.VERSION.SDK_INT >= 21) {
new MobileNetRequestManager().switchToMobile_L(context, 3000, new MobileNetRequestManager.SwitchToMobileListener() {
@Override
public void onFail(int i, String str3, long j) {
if (UaidTracker.this.isLoggerEnable) {
Log.e(UaidTracker.TAG, "====switchToMobile_L===Failed:" + str3);
}
}
@Override
public void onSuccess(Network network, long j) {
UaidTracker.this.requestToken(context, str, str2, false, network);
}
});
} else {
UaidTracker.this.requestToken(context, str, str2, true, null);
}
}
}
});
}
public String getIdToken(Context context, String str, String str2) {
String load = getCacheHandler(context, str, str2).load();
if (TextUtils.isEmpty(load)) {
return null;
}
try {
JSONObject jSONObject = new JSONObject(load);
long j = jSONObject.getLong(UAID_EXPIRED_TIME_KEY);
boolean z = jSONObject.getBoolean(UAID_ISUSABLE_KEY);
if (j > System.currentTimeMillis() && !z) {
return jSONObject.getJSONObject(UAID_TOKENS_KEY).toString();
}
} catch (JSONException unused) {
}
return null;
}
public boolean isUsable(Context context, String str, String str2) {
try {
return new JSONObject(getCacheHandler(context, str, str2).load()).getBoolean(UAID_ISUSABLE_KEY);
} catch (JSONException unused) {
return false;
}
}
public void setEnable(boolean z) {
isTackerEnable = z;
}
public void setKey(String str, String str2, String str3) {
this.cmccAppID = str;
this.cmccAppKey = str2;
this.cuccAppID = str3;
}
public void setLoggerEnable(boolean z) {
this.isLoggerEnable = z;
}
public void setUsable(Context context, String str, String str2) {
CacheHandler cacheHandler = getCacheHandler(context, str, str2);
try {
JSONObject jSONObject = new JSONObject(cacheHandler.load());
jSONObject.put(UAID_ISUSABLE_KEY, true);
cacheHandler.save(jSONObject.toString());
} catch (JSONException unused) {
}
}
public void updateIdTokens(Context context, String str, String str2) {
if (!isTackerEnable || TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
return;
}
String load = getCacheHandler(context, str, str2).load();
if (TextUtils.isEmpty(load)) {
Log.i(TAG, "Token===empty====");
switchToMobileNet(context, str, str2);
return;
}
if (this.isLoggerEnable) {
Log.w(TAG, "updateIdTokens:" + load);
}
try {
JSONObject jSONObject = new JSONObject(load);
long j = jSONObject.getLong(UAID_EXPIRED_TIME_KEY);
boolean z = jSONObject.getBoolean(UAID_ISUSABLE_KEY);
if (j >= System.currentTimeMillis() || z) {
return;
}
Log.w(TAG, "requestToken===过期且未被使用====");
switchToMobileNet(context, str, str2);
} catch (JSONException e) {
e.printStackTrace();
}
}
}