Booty Calls v1.2.156版本的 MD5 值为:919c7e4dc831ea1adbaf506a3cc1a198
以下内容为反编译后的 NutakuUtil.java 源代码,内容仅作参考
package com.nutaku.game.sdk.util;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Process;
import android.os.StatFs;
import android.widget.Toast;
import com.broadcom.bt.util.io.IOUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.nutaku.game.sdk.NutakuSdk;
import com.nutaku.game.sdk.auth.NutakuUserInfo;
import com.nutaku.game.sdk.customapi.model.CustomPromotion;
import com.nutaku.game.sdk.util.Constants;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public final class NutakuUtil {
private static final String IGNORED_UPDATE_VERSION_CODE_FILE = "sdk_ignored_update";
private NutakuUtil() {
}
public static String join(Iterable<?> iterable, String str) {
StringBuilder sb = new StringBuilder();
for (Object obj : iterable) {
if (sb.length() > 0) {
sb.append(str);
}
sb.append(obj.toString());
}
return sb.toString();
}
public static String getMobileApiEndpoint() {
char c;
String environment = NutakuSdk.getEnvironment();
int hashCode = environment.hashCode();
if (hashCode != 109757182) {
if (hashCode == 1865400007 && environment.equals(Constants.Keys.ENVIRONMENT_SANDBOX)) {
c = 1;
}
c = 65535;
} else {
if (environment.equals(Constants.Keys.ENVIRONMENT_STAGE)) {
c = 0;
}
c = 65535;
}
return c != 0 ? c != 1 ? Constants.MobileApiEndpoint.RELEASE : Constants.MobileApiEndpoint.SANDBOX : Constants.MobileApiEndpoint.STAGE;
}
public static String getSocialEndpoint() {
char c;
String environment = NutakuSdk.getEnvironment();
int hashCode = environment.hashCode();
if (hashCode != 109757182) {
if (hashCode == 1865400007 && environment.equals(Constants.Keys.ENVIRONMENT_SANDBOX)) {
c = 1;
}
c = 65535;
} else {
if (environment.equals(Constants.Keys.ENVIRONMENT_STAGE)) {
c = 0;
}
c = 65535;
}
return c != 0 ? c != 1 ? Constants.OsapiEndpoint.RELEASE : Constants.OsapiEndpoint.SANDBOX : Constants.OsapiEndpoint.STAGE;
}
public static String getFrontendDomain() {
char c;
String environment = NutakuSdk.getEnvironment();
int hashCode = environment.hashCode();
if (hashCode != 109757182) {
if (hashCode == 1865400007 && environment.equals(Constants.Keys.ENVIRONMENT_SANDBOX)) {
c = 1;
}
c = 65535;
} else {
if (environment.equals(Constants.Keys.ENVIRONMENT_STAGE)) {
c = 0;
}
c = 65535;
}
return c != 0 ? c != 1 ? Constants.FrontendDomain.RELEASE : Constants.FrontendDomain.SANDBOX : Constants.FrontendDomain.STAGE;
}
public static String getPromotionEndPoint() {
char c;
String environment = NutakuSdk.getEnvironment();
int hashCode = environment.hashCode();
if (hashCode != 109757182) {
if (hashCode == 1865400007 && environment.equals(Constants.Keys.ENVIRONMENT_SANDBOX)) {
c = 1;
}
c = 65535;
} else {
if (environment.equals(Constants.Keys.ENVIRONMENT_STAGE)) {
c = 0;
}
c = 65535;
}
return (c == 0 || c == 1) ? "http://cdn-updater.nutaku.net/androidsdk/stage/promotions/promotions.json" : Constants.PromotionEndPoint.RELEASE;
}
public static void setApkUpdateDialogVisibility(boolean z) {
writeToLocalStoredFile(IGNORED_UPDATE_VERSION_CODE_FILE, z ? "0" : Long.toString(NutakuSdk.getVersionConfig().getCode()));
}
public static boolean shouldShowApkUpdateDialog() {
if (NutakuSdk.getApkVersionCode() >= NutakuSdk.getVersionConfig().getCode()) {
return false;
}
if (NutakuSdk.getVersionConfig().isForceUpdate()) {
return true;
}
try {
String readFromLocalStoredFile = readFromLocalStoredFile(IGNORED_UPDATE_VERSION_CODE_FILE);
if (!isEmpty(readFromLocalStoredFile)) {
return Long.parseLong(readFromLocalStoredFile) < NutakuSdk.getVersionConfig().getCode();
}
} catch (Exception unused) {
}
return true;
}
public static boolean isEnoughFreeStorageAvailable(String str, long j) {
return !isEmpty(str) && j < new StatFs(str).getAvailableBytes();
}
public static void logoutAndExit(Activity activity) {
Context baseContext = activity.getBaseContext();
String str = String.format(Constants.WebUrls.LOGOUT_URL, getFrontendDomain()) + "?appId=" + NutakuSdk.getAppId() + "&sdkVersion=" + Constants.SDK_VERSION + "&prompt=consent&scheme=" + baseContext.getPackageName();
NutakuUserInfo.clearAutoLoginData();
Toast.makeText(baseContext, "You are now logging out...", 1).show();
activity.finishAffinity();
activity.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str)));
Process.killProcess(Process.myPid());
System.exit(0);
}
public static boolean isEmpty(String str) {
return str == null || "".equals(str) || "null".equals(str) || "\"\"".equals(str);
}
public static boolean checkNetworkConnect(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
if (connectivityManager == null) {
return false;
}
if (Build.VERSION.SDK_INT >= 23) {
NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork());
if (networkCapabilities != null) {
return networkCapabilities.hasTransport(1) || networkCapabilities.hasTransport(0) || networkCapabilities.hasTransport(4);
}
return false;
}
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
public static void showErrorDialog(final Activity activity, String str, String str2, boolean z) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(str);
builder.setMessage(str2);
if (z) {
builder.setPositiveButton("OK (Close App)", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
activity.moveTaskToBack(true);
Process.killProcess(Process.myPid());
}
});
} else {
builder.setPositiveButton("OK (Close)", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
activity.finish();
}
});
}
builder.show();
}
public static String readFromLocalStoredFile(String str) {
try {
FileInputStream openFileInput = NutakuSdk.getSdkContext().openFileInput(str);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(openFileInput));
StringBuilder sb = new StringBuilder();
boolean z = true;
while (true) {
String readLine = bufferedReader.readLine();
if (readLine != null) {
if (z) {
z = false;
} else {
sb.append(IOUtils.LINE_SEPARATOR_UNIX);
}
sb.append(readLine);
} else {
openFileInput.close();
return sb.toString();
}
}
} catch (FileNotFoundException unused) {
return null;
} catch (Exception e) {
e.printStackTrace();
Log.e("Error when reading contents for locally stored file named " + str + ". Exception message: " + e.getMessage());
return null;
}
}
public static void writeToLocalStoredFile(String str, String str2) {
try {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(NutakuSdk.getSdkContext().openFileOutput(str, 0));
outputStreamWriter.write(str2);
outputStreamWriter.close();
} catch (Exception e) {
e.printStackTrace();
Log.e("Error when writing contents for locally stored file named " + str + ". Exception message: " + e.getMessage());
}
}
public static Bitmap getBitmap(String str) throws IOException {
return BitmapFactory.decodeStream(new URL(str).openConnection().getInputStream());
}
public static void writeToFile(Context context, String str, String str2) {
try {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput(str, 0));
outputStreamWriter.write(str2);
outputStreamWriter.close();
} catch (IOException unused) {
}
}
public static String readFromFile(Context context, String str) {
try {
FileInputStream openFileInput = context.openFileInput(str);
if (openFileInput == null) {
return "";
}
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(openFileInput));
StringBuilder sb = new StringBuilder();
while (true) {
String readLine = bufferedReader.readLine();
if (readLine != null) {
sb.append(IOUtils.LINE_SEPARATOR_UNIX);
sb.append(readLine);
} else {
openFileInput.close();
return sb.toString();
}
}
} catch (Exception unused) {
return "";
}
}
public static void saveCustomPromotion(Context context, CustomPromotion customPromotion) {
try {
List customPromotionList = getCustomPromotionList(context);
if (customPromotionList == null) {
customPromotionList = new ArrayList();
}
if (customPromotion != null) {
customPromotionList.add(customPromotion);
}
writeToFile(context, "promotion.txt", new Gson().toJson(customPromotionList));
} catch (Exception unused) {
}
}
public static List<CustomPromotion> getCustomPromotionList(Context context) {
try {
String readFromFile = readFromFile(context, "promotion.txt");
if (isEmpty(readFromFile)) {
return null;
}
return (List) new Gson().fromJson(readFromFile, new TypeToken<List<CustomPromotion>>() {
}.getType());
} catch (Exception unused) {
return null;
}
}
public static void crossDeeplinkToNASOrWebGamePage(Context context, String str) {
if (crossDeeplinkToNASGamePage(context, str)) {
return;
}
crossDeeplinkToWebGamePage(context, str);
}
private static void crossDeeplinkToWebGamePage(Context context, String str) {
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("https://www.nutaku.net/games/" + str + "/"));
intent.setFlags(268435456);
context.startActivity(intent);
}
private static boolean crossDeeplinkToNASGamePage(Context context, String str) {
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse("com.project.nutaku://deeplink.gamedetails/param?titleId=" + str));
intent.setFlags(335544320);
if (intent.resolveActivity(context.getPackageManager()) != null) {
try {
context.getPackageManager().getApplicationInfo(Constants.NUTAKU_STORE_PACKAGE, 0);
context.startActivity(intent);
return true;
} catch (PackageManager.NameNotFoundException unused) {
Log.d("com.project.nutaku not installed");
}
}
return false;
}
}