package csdk.glucentralservices.util; import android.app.Activity; import android.app.ActivityManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.graphics.Point; import android.net.Uri; import android.os.Build; import android.preference.PreferenceManager; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.facebook.internal.AnalyticsEvents; import com.google.android.gms.drive.DriveFile; import com.google.android.ump.ConsentForm; import com.google.android.ump.ConsentInformation; import com.google.android.ump.ConsentRequestParameters; import com.google.android.ump.FormError; import com.google.android.ump.UserMessagingPlatform; import com.mbridge.msdk.foundation.entity.CampaignEx; import com.mbridge.msdk.foundation.tools.SameMD5; import csdk.glucentralservices.consent.ConsentUI; import csdk.glucentralservices.consent.IConsentListener; import csdk.glucentralservices.devicetiers.DeviceTier; import csdk.glucentralservices.devicetiers.DeviceTiers; import csdk.glucentralservices.devicetiers.DeviceUtil; import csdk.glucentralservices.kvstore.StringStore; import csdk.glucentralservices.network.DownloadInfo; import csdk.glucentralservices.network.Downloader; import csdk.glucentralservices.network.NetworkResponse; import csdk.glucentralservices.network.NetworkUtils; import csdk.glucentralservices.webview.IWebViewListener; import csdk.glucentralservices.webview.WebView; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.nio.ByteBuffer; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.Timer; import java.util.TimerTask; import java.util.UUID; /* loaded from: classes4.dex */ public class AndroidPlatform { static boolean mCMPRegionDetected; static boolean mCMPShouldShow; private ActivityLifecycleCallbacks mActivityLifeCycleCallbacks; private final Context mContext; private boolean mIsAvailable = true; private final Timer mTimer = new Timer("GluCentralServices-AndroidPlatform"); private Downloader mDownloader = null; /* JADX INFO: Access modifiers changed from: private */ public native void deleteConsentCallbacks(long j, long j2); /* JADX INFO: Access modifiers changed from: private */ public native void onApplicationEvent(String str); /* JADX INFO: Access modifiers changed from: private */ public native void onConsentEvent(long j, String str); /* JADX INFO: Access modifiers changed from: private */ public native void onDownloadResponse(long j, int i, String str); /* JADX INFO: Access modifiers changed from: private */ public native void onHTTPResponse(long j, int i, byte[] bArr, Map map); private native void onRequestCMPConsentInfoComplete(long j, boolean z); /* JADX INFO: Access modifiers changed from: private */ public native void onShowCMPConsentFormComplete(long j, boolean z, String str, String str2, String str3, String str4, String str5); /* JADX INFO: Access modifiers changed from: private */ public native void onShowConsentComplete(long j, String str); /* JADX INFO: Access modifiers changed from: private */ public native void onShowWebViewComplete(long j, String str, String str2); /* JADX INFO: Access modifiers changed from: private */ public native void onTimerEvent(long j); public String getLocale() { return ""; } public AndroidPlatform(Context context) { this.mContext = context.getApplicationContext(); } public void destroy() { this.mIsAvailable = false; Downloader downloader = this.mDownloader; if (downloader != null) { downloader.destroy(); } this.mTimer.cancel(); ActivityLifecycleCallbacks activityLifecycleCallbacks = this.mActivityLifeCycleCallbacks; if (activityLifecycleCallbacks != null) { activityLifecycleCallbacks.destroy(); } } public void registerApplicationEvent() { this.mActivityLifeCycleCallbacks = new ActivityLifecycleCallbacks(this.mContext, new IAction2() { // from class: csdk.glucentralservices.util.AndroidPlatform.1 @Override // csdk.glucentralservices.util.IAction2 public void apply(String str, Activity activity) { if (AndroidPlatform.this.mIsAvailable) { if ("onApplicationResumed".equals(str)) { AndroidPlatform.this.onApplicationEvent(CampaignEx.JSON_NATIVE_VIDEO_RESUME); } else if ("onApplicationPaused".equals(str)) { AndroidPlatform.this.onApplicationEvent(CampaignEx.JSON_NATIVE_VIDEO_PAUSE); } } } }); } public void sendHTTPRequest(String str, final String str2, String[] strArr, final String str3, final long j, final long j2) throws MalformedURLException { final URL url = new URL(str); final HashMap hashMap = new HashMap(); if (strArr != null) { for (int i = 0; i < strArr.length; i += 2) { hashMap.put(strArr[i], strArr[i + 1]); } } runAsync(new Runnable() { // from class: csdk.glucentralservices.util.AndroidPlatform.2 @Override // java.lang.Runnable public void run() { NetworkResponse sendRequest = NetworkUtils.sendRequest(str2, url, hashMap, str3, j); AndroidPlatform.this.onHTTPResponse(j2, sendRequest.code, sendRequest.body, sendRequest.responseHeaders); } }); } public void downloadFile(String str, final String str2, final long j, final long j2, boolean z) throws MalformedURLException { final URL url = new URL(str); if (!z) { runAsync(new Runnable() { // from class: csdk.glucentralservices.util.AndroidPlatform.3 @Override // java.lang.Runnable public void run() { File file = new File(str2); String str3 = ""; if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { AndroidPlatform.this.onDownloadResponse(j2, 0, ""); return; } int i = NetworkUtils.downloadIntoFile(url, new File(str2), j).code; if (i >= 200 && i < 300) { str3 = str2; } AndroidPlatform.this.onDownloadResponse(j2, i, str3); } }); return; } if (this.mDownloader == null) { Downloader downloader = new Downloader(this.mContext); this.mDownloader = downloader; downloader.init(); } this.mDownloader.download(str, str2, new Downloader.DownloadListener() { // from class: csdk.glucentralservices.util.AndroidPlatform.4 @Override // csdk.glucentralservices.network.Downloader.DownloadListener public void onDownloadComplete(boolean z2, DownloadInfo downloadInfo) { int i; String str3; if (z2) { str3 = downloadInfo.destinationPath; i = 200; } else { i = 0; str3 = ""; } AndroidPlatform.this.onDownloadResponse(j2, i, str3); } }); } public void scheduleEvent(long j, final long j2) { this.mTimer.schedule(new TimerTask() { // from class: csdk.glucentralservices.util.AndroidPlatform.5 @Override // java.util.TimerTask, java.lang.Runnable public void run() { AndroidPlatform.this.onTimerEvent(j2); } }, j); } public String privateFilePath() { return this.mContext.getFilesDir().toString(); } public boolean checkPrivateDirectoryExists(String str, boolean z) { File file = new File(str); return !file.exists() && z && file.mkdirs(); } public boolean removePrivateData(String str) { File file = new File(str); if (file.isDirectory() && file.list().length > 0) { for (String str2 : file.list()) { } } return false; } public String getApplicationVersion() { try { return this.mContext.getPackageManager().getPackageInfo(this.mContext.getPackageName(), 0).versionName; } catch (PackageManager.NameNotFoundException unused) { return ""; } } public String getApplicationID() { return this.mContext.getPackageName(); } public String[] readProperties(String str, String[] strArr) { SharedPreferences sharedPreferences = this.mContext.getSharedPreferences(str, 0); ArrayList arrayList = new ArrayList(strArr.length * 2); for (String str2 : strArr) { String string = sharedPreferences.getString(str2, null); if (string != null) { arrayList.add(str2); arrayList.add(string); } } return (String[]) arrayList.toArray(new String[arrayList.size()]); } public void writeProperties(String str, String[] strArr) { SharedPreferences.Editor edit = this.mContext.getSharedPreferences(str, 0).edit(); for (int i = 0; i < strArr.length; i += 2) { try { edit.putString(strArr[i], strArr[i + 1]); } finally { edit.apply(); } } } public String readSharedProperty(String str) { SharedPreferences sharedPreferences = this.mContext.getSharedPreferences("glu-analytics", 0); if (!sharedPreferences.contains(str)) { return ""; } try { return sharedPreferences.getBoolean(str, false) ? "true" : "false"; } catch (ClassCastException unused) { return ""; } } public void md5(ByteBuffer byteBuffer, ByteBuffer byteBuffer2) throws NoSuchAlgorithmException { byte[] bArr = new byte[1024]; MessageDigest messageDigest = MessageDigest.getInstance(SameMD5.TAG); while (byteBuffer.remaining() > 0) { int min = Math.min(1024, byteBuffer.remaining()); byteBuffer.get(bArr, 0, min); messageDigest.update(bArr, 0, min); } byteBuffer2.put(messageDigest.digest()); } public int getDeviceTier() { DeviceTier deviceTier = DeviceTiers.getDeviceTier(this.mContext); return (deviceTier.fallback ? 256 : 0) | deviceTier.tier; } public int getCpuCoreCount() { return DeviceUtil.getCpuCount(); } public String getGpuDeviceVendor() { DeviceUtil.GlesData glesData = DeviceUtil.getGlesData(); return glesData != null ? glesData.gpuVendor : AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_UNKNOWN; } public String getGpuDeviceName() { DeviceUtil.GlesData glesData = DeviceUtil.getGlesData(); return glesData != null ? glesData.gpuRenderer : AnalyticsEvents.PARAMETER_DIALOG_OUTCOME_VALUE_UNKNOWN; } public double getRamAmount() { try { ((ActivityManager) this.mContext.getSystemService("activity")).getMemoryInfo(new ActivityManager.MemoryInfo()); return (r0.totalMem / 1024.0d) / 1024.0d; } catch (Exception unused) { return 0.0d; } } public String getCpuName() { return Build.SUPPORTED_ABIS[0]; } public String getScreenSize() { Point screenSize = DeviceUtil.getScreenSize(this.mContext); return Math.min(screenSize.x, screenSize.y) + "x" + Math.max(screenSize.x, screenSize.y); } public String getETC2IfSupported() { DeviceUtil.GlesData glesData = DeviceUtil.getGlesData(); return glesData != null ? glesData.supportedTextureFormat : ""; } public String getLanguage() { Locale locale = Locale.getDefault(); if (locale.getCountry().equalsIgnoreCase("tw") || locale.getCountry().equalsIgnoreCase("hk")) { return locale.getLanguage() + "-hant"; } if (locale.getLanguage().equalsIgnoreCase("es") || locale.getLanguage().equalsIgnoreCase("pt")) { return locale.getLanguage() + "-" + locale.getCountry(); } return locale.getLanguage(); } public void showConsent(final long j, final long j2, final Activity activity, final String str) { if (activity == null) { throw new IllegalArgumentException("activity can't be null"); } Common.runOnUIThread(new Runnable() { // from class: csdk.glucentralservices.util.AndroidPlatform.6 @Override // java.lang.Runnable public void run() { try { new ConsentUI(activity).showConsent(str, new IConsentListener() { // from class: csdk.glucentralservices.util.AndroidPlatform.6.1 @Override // csdk.glucentralservices.consent.IConsentListener public void onConsentStatusReceived(String str2, Throwable th) { if (th != null) { AnonymousClass6 anonymousClass6 = AnonymousClass6.this; AndroidPlatform.this.onShowConsentComplete(j, th.getMessage()); } else { AnonymousClass6 anonymousClass62 = AnonymousClass6.this; AndroidPlatform.this.onShowConsentComplete(j, str2); } AnonymousClass6 anonymousClass63 = AnonymousClass6.this; AndroidPlatform.this.deleteConsentCallbacks(j, j2); } @Override // csdk.glucentralservices.consent.IConsentListener public void onConsentEventReceived(String str2) { AnonymousClass6 anonymousClass6 = AnonymousClass6.this; AndroidPlatform.this.onConsentEvent(j2, str2); } }); } catch (Exception e) { AndroidPlatform.this.onShowConsentComplete(j, e.getMessage()); AndroidPlatform.this.deleteConsentCallbacks(j, j2); } } }); } public void showWebView(final long j, final Activity activity, final String str, final String str2) { if (activity == null) { throw new IllegalArgumentException("activity can't be null"); } Common.runOnUIThread(new Runnable() { // from class: csdk.glucentralservices.util.AndroidPlatform.7 @Override // java.lang.Runnable public void run() { try { new WebView(activity).show(str, str2, new IWebViewListener() { // from class: csdk.glucentralservices.util.AndroidPlatform.7.1 @Override // csdk.glucentralservices.webview.IWebViewListener public void onStatusReceived(String str3, Throwable th) { AnonymousClass7 anonymousClass7 = AnonymousClass7.this; AndroidPlatform.this.onShowWebViewComplete(j, str3, th != null ? th.getMessage() : null); } }); } catch (Exception e) { AndroidPlatform.this.onShowWebViewComplete(j, null, e.getMessage()); } } }); } /* JADX INFO: Access modifiers changed from: private */ public void processCMPConsentResult(long j, @Nullable FormError formError) { boolean z = UserMessagingPlatform.getConsentInformation(this.mContext).getPrivacyOptionsRequirementStatus() == ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED; if (formError != null) { onShowCMPConsentFormComplete(j, z, null, null, null, null, String.format("%s: %s", Integer.valueOf(formError.getErrorCode()), formError.getMessage())); } else { SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.mContext); onShowCMPConsentFormComplete(j, z, defaultSharedPreferences.getString("IABTCF_PurposeConsents", ""), defaultSharedPreferences.getString("IABTCF_PurposeLegitimateInterests", ""), defaultSharedPreferences.getString("IABTCF_VendorConsents", ""), defaultSharedPreferences.getString("IABTCF_AddtlConsent", ""), null); } } /* renamed from: csdk.glucentralservices.util.AndroidPlatform$8, reason: invalid class name */ public class AnonymousClass8 implements Runnable { final /* synthetic */ Activity val$activity; final /* synthetic */ long val$nativeCallback; final /* synthetic */ boolean val$showSettings; final /* synthetic */ boolean val$underAge; public AnonymousClass8(boolean z, Activity activity, long j, boolean z2) { this.val$showSettings = z; this.val$activity = activity; this.val$nativeCallback = j; this.val$underAge = z2; } @Override // java.lang.Runnable public void run() { try { if (this.val$showSettings) { UserMessagingPlatform.showPrivacyOptionsForm(this.val$activity, new ConsentForm.OnConsentFormDismissedListener() { // from class: csdk.glucentralservices.util.AndroidPlatform.8.1 @Override // com.google.android.ump.ConsentForm.OnConsentFormDismissedListener public void onConsentFormDismissed(@Nullable FormError formError) { AnonymousClass8 anonymousClass8 = AnonymousClass8.this; AndroidPlatform.this.processCMPConsentResult(anonymousClass8.val$nativeCallback, formError); } }); } else if (AndroidPlatform.mCMPShouldShow && !this.val$underAge) { UserMessagingPlatform.loadAndShowConsentFormIfRequired(this.val$activity, new ConsentForm.OnConsentFormDismissedListener() { // from class: csdk.glucentralservices.util.AndroidPlatform.8.2 @Override // com.google.android.ump.ConsentForm.OnConsentFormDismissedListener public void onConsentFormDismissed(@Nullable FormError formError) { AnonymousClass8 anonymousClass8 = AnonymousClass8.this; AndroidPlatform.this.processCMPConsentResult(anonymousClass8.val$nativeCallback, formError); } }); } else { UserMessagingPlatform.getConsentInformation(AndroidPlatform.this.mContext).requestConsentInfoUpdate(this.val$activity, new ConsentRequestParameters.Builder().setTagForUnderAgeOfConsent(this.val$underAge).build(), new ConsentInformation.OnConsentInfoUpdateSuccessListener() { // from class: csdk.glucentralservices.util.AndroidPlatform.8.3 @Override // com.google.android.ump.ConsentInformation.OnConsentInfoUpdateSuccessListener public void onConsentInfoUpdateSuccess() { UserMessagingPlatform.loadAndShowConsentFormIfRequired(AnonymousClass8.this.val$activity, new ConsentForm.OnConsentFormDismissedListener() { // from class: csdk.glucentralservices.util.AndroidPlatform.8.3.1 @Override // com.google.android.ump.ConsentForm.OnConsentFormDismissedListener public void onConsentFormDismissed(@Nullable FormError formError) { AnonymousClass8 anonymousClass8 = AnonymousClass8.this; AndroidPlatform.this.processCMPConsentResult(anonymousClass8.val$nativeCallback, formError); } }); } }, new ConsentInformation.OnConsentInfoUpdateFailureListener() { // from class: csdk.glucentralservices.util.AndroidPlatform.8.4 @Override // com.google.android.ump.ConsentInformation.OnConsentInfoUpdateFailureListener public void onConsentInfoUpdateFailure(@NonNull FormError formError) { AnonymousClass8 anonymousClass8 = AnonymousClass8.this; AndroidPlatform.this.processCMPConsentResult(anonymousClass8.val$nativeCallback, formError); } }); } } catch (Exception e) { AndroidPlatform.this.onShowCMPConsentFormComplete(this.val$nativeCallback, false, null, null, null, null, e.getMessage()); } } } public void showCMPConsentForm(long j, Activity activity, boolean z, boolean z2) { if (activity == null) { throw new IllegalArgumentException("activity can't be null"); } Common.runOnUIThread(new AnonymousClass8(z, activity, j, z2)); } /* JADX INFO: Access modifiers changed from: private */ public void onCMPRegionDetected(long j, boolean z) { mCMPShouldShow = z; mCMPRegionDetected = true; onRequestCMPConsentInfoComplete(j, z); } public void requestCMPConsentInfo(final long j, final Activity activity) { if (activity == null) { throw new IllegalArgumentException("activity can't be null"); } if (mCMPRegionDetected) { onRequestCMPConsentInfoComplete(j, mCMPShouldShow); } else { Common.runOnUIThread(new Runnable() { // from class: csdk.glucentralservices.util.AndroidPlatform.9 @Override // java.lang.Runnable public void run() { try { ConsentRequestParameters build = new ConsentRequestParameters.Builder().setTagForUnderAgeOfConsent(false).build(); final ConsentInformation consentInformation = UserMessagingPlatform.getConsentInformation(AndroidPlatform.this.mContext); consentInformation.requestConsentInfoUpdate(activity, build, new ConsentInformation.OnConsentInfoUpdateSuccessListener() { // from class: csdk.glucentralservices.util.AndroidPlatform.9.1 @Override // com.google.android.ump.ConsentInformation.OnConsentInfoUpdateSuccessListener public void onConsentInfoUpdateSuccess() { boolean z = consentInformation.getConsentStatus() != 1; AnonymousClass9 anonymousClass9 = AnonymousClass9.this; AndroidPlatform.this.onCMPRegionDetected(j, z); } }, new ConsentInformation.OnConsentInfoUpdateFailureListener() { // from class: csdk.glucentralservices.util.AndroidPlatform.9.2 @Override // com.google.android.ump.ConsentInformation.OnConsentInfoUpdateFailureListener public void onConsentInfoUpdateFailure(@NonNull FormError formError) { AnonymousClass9 anonymousClass9 = AnonymousClass9.this; AndroidPlatform.this.onCMPRegionDetected(j, false); } }); } catch (Exception unused) { AndroidPlatform.this.onCMPRegionDetected(j, false); } } }); } } public void openURL(final String str) { Common.runOnUIThread(new Runnable() { // from class: csdk.glucentralservices.util.AndroidPlatform.10 @Override // java.lang.Runnable public void run() { Intent data = new Intent().setAction("android.intent.action.VIEW").setData(Uri.parse(str)); data.setFlags(DriveFile.MODE_READ_ONLY); AndroidPlatform.this.mContext.startActivity(data); } }); } public void presentToast(final String str) { Common.runOnUIThread(new Runnable() { // from class: csdk.glucentralservices.util.AndroidPlatform.11 @Override // java.lang.Runnable public void run() { Toast.makeText(AndroidPlatform.this.mContext, str, 1).show(); } }); } public boolean isNewInstall() { StringBuilder sb = new StringBuilder(); sb.append(privateFilePath()); sb.append("/tags"); return !new File(sb.toString()).exists(); } public String readAssetAsString(String str) throws IOException { try { InputStream open = this.mContext.getAssets().open(str); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(open)); try { StringBuilder sb = new StringBuilder(open.available()); char[] cArr = new char[16384]; while (true) { int read = bufferedReader.read(cArr); if (read >= 0) { sb.append(cArr, 0, read); } else { return sb.toString(); } } } finally { bufferedReader.close(); } } catch (Exception unused) { return null; } } public String getFromStringStore(String str) { return StringStore.get(str); } public void setToStringStore(String str, String str2) { StringStore.set(str, str2); } public String generateUUID() { return UUID.randomUUID().toString(); } private void runAsync(Runnable runnable) { new Thread(runnable).start(); } }