Commit f20ea6f6 authored by bixing's avatar bixing

gp_admob

parent 92e4f154
......@@ -100,7 +100,6 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-process:2.6.2'
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
implementation 'com.or.ange:likepal:2.2.2'
......
......@@ -280,3 +280,16 @@
-keep public class com.android.gem.core.Node { *; }
-keep public class com.android.gem.core.Event { *; }
-keep public class com.tencent.matrix.**{*;}
-keep public class com.tencent.mrs.**{*;}
# Google
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-dontwarn com.tencent.bugly.**
-keep public class com.tencent.bugly.**{*;}
......@@ -136,8 +136,8 @@
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="xsplash"
android:scheme="std" />
android:host="ggxsplash"
android:scheme="ggstd" />
</intent-filter>
</activity>
<activity
......
......@@ -16,8 +16,6 @@ interface XGENAdData {
void setUuid(String uuid);
void setAlertWindowOpen(boolean open);
void initMediaApp(String adAppId_channelId);
void closeActivity();
......@@ -30,7 +28,14 @@ interface XGENAdData {
void setNCanNextRequestAd(boolean can);
boolean adIsLoading();
void showSplashBg(String c_pkgName, String path, long closeTime);
void closeSplashBg();
void startKp(boolean start, boolean startGp);
void startKp2(int start, int startGp);
void setReportS(int i);
void transferData(int type, String data);
}
\ No newline at end of file
......@@ -13,7 +13,6 @@ import com.gem.media.splash.base.utils.ALog;
public class AProvider extends ContentProvider {
@Override
public boolean onCreate() {
ALog.w("AProvider","onCreate");
return false;
}
......
......@@ -98,7 +98,6 @@ public class HActivity extends Activity {
map.put("url", url);
}
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_CREATE, map);
}
@Override
......@@ -127,7 +126,6 @@ public class HActivity extends Activity {
return;
}
ALog.d("HActivity", "url " + url);
BarUtils.setStatusBarColor(this, Color.WHITE);
BarUtils.setStatusBarLightMode(this, true);
EditText editText = findViewById(R.id.edtext);
line = findViewById(R.id.line);
......@@ -177,7 +175,6 @@ public class HActivity extends Activity {
map.put("url", endUrl);
map.put("text", text);
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_PAGE_SEARCH_TEXT, map);
} catch (Exception e) {
}
......@@ -317,7 +314,6 @@ public class HActivity extends Activity {
Map<String, String> map = new HashMap<>();
map.put("url", url);
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_PAGE_START, map);
} catch (Exception e) {
e.printStackTrace();
}
......@@ -343,7 +339,6 @@ public class HActivity extends Activity {
Map<String, String> map = new HashMap<>();
map.put("url", url);
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_PAGE_FINISH, map);
} catch (Exception e) {
}
......@@ -358,7 +353,6 @@ public class HActivity extends Activity {
map.put("r", errorResponse.getReasonPhrase());
map.put("code", String.valueOf(errorResponse.getStatusCode()));
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_PAGE_ERROR, map);
} catch (Exception e) {
}
......@@ -372,7 +366,6 @@ public class HActivity extends Activity {
map.put("url", error.getUrl());
map.put("r", "onReceivedSslError");
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_PAGE_ERROR, map);
} catch (Exception e) {
}
......@@ -387,7 +380,6 @@ public class HActivity extends Activity {
map.put("r", description);
map.put("code", String.valueOf(errorCode));
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_PAGE_ERROR, map);
} catch (Exception e) {
}
......@@ -403,7 +395,6 @@ public class HActivity extends Activity {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
map.put("r", error.getDescription().toString());
}
StatsStaticHelper.onEvent(Constants.H_PAGE_ERROR, map);
} catch (Exception e) {
}
......@@ -501,7 +492,6 @@ public class HActivity extends Activity {
long t = (System.currentTimeMillis() - currentTime) / 1000;
map.put("t", String.valueOf(t));
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_SHOW_TIME, map);
ALog.d("HActivity", "onStop");
}
......
......@@ -70,11 +70,9 @@ public class NativeAdWindManager {
PackageManager pm = context.getPackageManager();
int granted = pm.checkPermission(Manifest.permission.SYSTEM_ALERT_WINDOW, context.getPackageName());
if (granted != PackageManager.PERMISSION_GRANTED) {
StatsStaticHelper.onEvent(Constants.N_WM_NOT_PER);
ALog.d("NativeAdWindManager", "create window not permission");
return;
} else {
StatsStaticHelper.onEvent(Constants.N_WM_PER);
}
if (false) {
if (windowManager == null) {
......
......@@ -69,7 +69,6 @@ public class NewHActivity extends Activity {
map.put("url", url);
}
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_CREATE, map);
}
private WebView webView;
......@@ -91,7 +90,6 @@ public class NewHActivity extends Activity {
return;
}
ALog.d("NewHActivity","url = " + url);
BarUtils.setStatusBarColor(this, Color.BLACK);
BarUtils.setStatusBarLightMode(this,false);
mProgressBar = findViewById(R.id.launch_progress);
layout = findViewById(R.id.layout);
......@@ -219,7 +217,6 @@ public class NewHActivity extends Activity {
Map<String, String> map = new HashMap<>();
map.put("url", url);
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_PAGE_START, map);
} catch (Exception e) {
e.printStackTrace();
}
......@@ -237,7 +234,6 @@ public class NewHActivity extends Activity {
Map<String, String> map = new HashMap<>();
map.put("url", url);
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_PAGE_FINISH, map);
} catch (Exception e) {
}
......@@ -252,7 +248,6 @@ public class NewHActivity extends Activity {
map.put("r", errorResponse.getReasonPhrase());
map.put("code", String.valueOf(errorResponse.getStatusCode()));
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_PAGE_ERROR, map);
} catch (Exception e) {
}
......@@ -266,7 +261,6 @@ public class NewHActivity extends Activity {
map.put("url", error.getUrl());
map.put("r", "onReceivedSslError");
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_PAGE_ERROR, map);
} catch (Exception e) {
}
......@@ -281,7 +275,6 @@ public class NewHActivity extends Activity {
map.put("r", description);
map.put("code", String.valueOf(errorCode));
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_PAGE_ERROR, map);
} catch (Exception e) {
}
......@@ -297,7 +290,6 @@ public class NewHActivity extends Activity {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
map.put("r", error.getDescription().toString());
}
StatsStaticHelper.onEvent(Constants.H_PAGE_ERROR, map);
} catch (Exception e) {
}
......@@ -354,7 +346,6 @@ public class NewHActivity extends Activity {
Map<String, String> map = new HashMap<>();
map.put("url", TextUtils.isEmpty(url) ? "url is null" : url);
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_PAGE_SEARCH_TEXT, map);
ALog.d("NewHActivity", "loadUrl url " + url +" from "+from);
} else {
ALog.d("NewHActivity","webView = null");
......@@ -392,7 +383,6 @@ public class NewHActivity extends Activity {
long t = (System.currentTimeMillis() - currentTime) / 1000;
map.put("t", String.valueOf(t));
map.put("pt", TextUtils.isEmpty(from) ? "old" : from);
StatsStaticHelper.onEvent(Constants.H_SHOW_TIME, map);
ALog.d("NewHActivity","onStop");
}
......
......@@ -5,20 +5,31 @@ import android.content.Context;
import android.content.Intent;
import com.gem.media.splash.base.utils.ALog;
import com.gem.media.util.SplashWindowViewManger;
import com.live.KpUtil;
import java.util.Objects;
public class ScreenBroadcastReceiver extends BroadcastReceiver {
long time = 0;
private static final int T = 1000;
@Override
public void onReceive(Context context, Intent intent) {
if (null != intent) {
ALog.d("ScreenBroadcastReceiver", "onReceive action =" + intent.getAction());
if (Objects.equals(intent.getAction(), Intent.ACTION_SCREEN_ON)) {
PViewManager.getInstance().showOrRemoveWindow();
if (Objects.equals(intent.getAction(), Intent.ACTION_SCREEN_OFF)
|| Objects.equals(intent.getAction(), Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
if (System.currentTimeMillis() - time > T) {
SplashWindowViewManger.getInstance().removeSplashWindowView(1);
time = System.currentTimeMillis();
}
if (Objects.equals(intent.getAction(), Intent.ACTION_SCREEN_OFF)) {
KpUtil.getInstance().setIsScreenOn(false);
}
} else if (Objects.equals(intent.getAction(), Intent.ACTION_SCREEN_ON)) {
KpUtil.getInstance().setIsScreenOn(true);
KpUtil.getInstance().startLive(context);
}
} else {
ALog.d("ScreenBroadcastReceiver", "intent == null" );
}
}
}
......@@ -5,6 +5,7 @@ import android.util.Log;
import com.gem.media.splash.base.utils.ALog;
import com.or.ange.dot.UsageStats;
import com.or.ange.dot.utils.LLog;
import java.util.HashMap;
import java.util.Map;
......@@ -26,7 +27,7 @@ public class StatsStaticHelper {
params.put("uuid", InitA.getInstance().getUuid());
UsageStats.onEvent(eventId, label, params);
} catch (Exception e) {
ALog.e(TAG,"onEvent 2 e :" + Log.getStackTraceString(e));
LLog.e(TAG,"onEvent 2 e :" + Log.getStackTraceString(e));
}
}
......@@ -36,7 +37,27 @@ public class StatsStaticHelper {
params.put("uuid", InitA.getInstance().getUuid());
UsageStats.onEvent(eventId, "", params);
} catch (Exception e) {
ALog.e(TAG,"onEvent 3 e :" + Log.getStackTraceString(e));
LLog.e(TAG,"onEvent 3 e :" + Log.getStackTraceString(e));
}
}
public static void reportOnEvent(String eventId) {
onEvent(eventId, new HashMap<>());
}
public static void reportOnEvent(String eventId, String label) {
reportOnEvent(eventId, label, new HashMap<>());
}
public static void reportOnEvent(String eventId, String label, Map<String, String> params) {
try {
params.put("uuid", InitA.getInstance().getUuid());
UsageStats.onEvent(eventId, label, params);
} catch (Exception e) {
LLog.e(TAG,"onEvent 2 e :" + Log.getStackTraceString(e));
}
}
}
......@@ -34,7 +34,7 @@ public class SystemDialogReceiver extends BroadcastReceiver {
long currentTime = System.currentTimeMillis();
if (currentTime - lastHomeKeyTime > HOME_KEY_DEBOUNCE_DELAY) {
lastHomeKeyTime = currentTime;
InitA.getInstance().cleanTask(BaseApplication.getApplication(), 0);
InitA.getInstance().cleanTask(BaseApplication.getApplication());
}
break;
}
......
......@@ -100,36 +100,4 @@ public class AdData {
mapHashMap.put(AdData.AD_TYPE_INTERSTITIAL, null);
}
public int getAdIdSize(String adType) {
if (mapHashMap == null || mapHashMap.isEmpty()) {
return -1;
}
List<String> data = mapHashMap.get(adType);
if (data == null || data.isEmpty()) {
return -1;
}
return data.size();
}
public boolean canLoadAdData(String adType) {
boolean can = false;
if (null == adTypes) {
adTypes = new ArrayList<>();
LLog.w("GEM_WZ", " canLoadAdData adTypes == null");
return false;
}
if (TextUtils.isEmpty(adType)) {
return false;
}
LLog.w("GEM_WZ", " canLoadAdData adTypes size == " +adTypes.size());
for (String type : adTypes) {
LLog.w("GEM_WZ", " canLoadAdData adTypes type == " +type +" "+adType);
if (!TextUtils.isEmpty(type) && type.equals(adType)) {
can = true;
break;
}
}
return can;
}
}
......@@ -38,6 +38,7 @@ public class AdManager {
private final Map<String, AdmobNativeManager> admobNativeManagers = new HashMap<>(5);
private boolean canNextAdRequest = true;
public void setCanNextAdRequest(boolean canNextAdRequest) {
......@@ -53,7 +54,6 @@ public class AdManager {
public boolean hasCache() {
return AdmobInterstitialManager.instance().isAdAvailable();
}
public boolean adIsLoading() {
return AdmobInterstitialManager.instance().isAdIsLoading();
}
......@@ -116,7 +116,6 @@ public class AdManager {
}
}
public void setData(JSONArray array) {
if (array == null) {
return;
......@@ -171,6 +170,7 @@ public class AdManager {
admobNativeManagers.put(AdmobNativeManager.P_1, admobNativeManager);
}
}
}
public AdmobNativeManager getAdmobNativeManager(String adPosition) {
......
......@@ -2,12 +2,12 @@ package com.gem.media.ad;
public interface AdStatusCallBack {
void onAdLoad(String type, String ad_type, String reason, long time, String adId, String scenario);
void onAdLoaded(String type, String ad_type, String reason, long time, String adId, String scenario);
void onNoAdError(String type, String ad_type, String reason, long time, String adId, String scenario);
void onAdShow(String type, String ad_type, String reason, long time, String adId, String scenario);
void onAdClick(String type, String ad_type, String reason, long time, String adId, String scenario);
void onAdDismiss(String type, String ad_type, String reason, long time, String adId, String scenario);
void onAdLoadTimeout(String type, String ad_type, String reason, long time, String adId);
void nextMediaAppAdReq(String type, String ad_type, String reason, long time, String adId, String scenario);
}
......@@ -12,7 +12,9 @@ import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.ads.cal.notes.manager.GoogleMobileAdsConsentManager;
import com.gem.media.StatsStaticHelper;
import com.gem.media.splash.base.crash.CountryUtil;
import com.gem.media.splash.base.protocol.AdCallback;
import com.gem.media.splash.base.protocol.Constants;
import com.google.android.gms.ads.AdError;
......@@ -81,7 +83,7 @@ public class AdmobInterstitialManager {
if (null != adStatusCallBack) {
adStatusCallBack.onNoAdError(Constants.NODE_ERROR, AD_TYPE, error, requestTime, mAdUnitId, Constants.SCENARIO_CHAPIN);
}
loadAd(context, loadIndex);
// loadAd(context, loadIndex);
}
@Override
......@@ -99,7 +101,7 @@ public class AdmobInterstitialManager {
adStatusCallBack.onAdLoaded(Constants.NODE_REQUEST_SUCCESS, AD_TYPE, "loaded", requestTime, mAdUnitId, Constants.SCENARIO_CHAPIN);
}
requestTime = System.currentTimeMillis();
loadIndex = 0;
// loadIndex = 0;
}
});
......@@ -210,28 +212,16 @@ public class AdmobInterstitialManager {
public void loadAd(Context context, int loadIndex) {
if (context == null) {
if (null != adStatusCallBack) {
adStatusCallBack.nextMediaAppAdReq(Constants.NODE_NEXT_MEDIA_AD_REQ, AD_TYPE, "context is null", -2, "", Constants.SCENARIO_CHAPIN);
}
return;
}
if (null != adStatusCallBack) {
adStatusCallBack.nextMediaAppAdReq(Constants.NODE_NEXT_MEDIA_AD_REQ, AD_TYPE, "loadAd admob chaping start", -2, "", Constants.SCENARIO_CHAPIN);
}
LLog.d(TAG, "loadAd admob chaping start.");
if (adIsLoading) {
LLog.d(TAG, "loadAd admob isLoading. "+AdmobInterstitialManager.mAdUnitId);
if (null != adStatusCallBack) {
adStatusCallBack.nextMediaAppAdReq(Constants.NODE_NEXT_MEDIA_AD_REQ, AD_TYPE, "adIsLoading", -2, AdmobInterstitialManager.mAdUnitId, Constants.SCENARIO_CHAPIN);
}
return;
}
if (isAdAvailable()) {
LLog.d(TAG, "loadAd admob chaping 3.");
if (null != adStatusCallBack) {
adStatusCallBack.nextMediaAppAdReq(Constants.NODE_NEXT_MEDIA_AD_REQ, AD_TYPE, "has cache", -2, AdmobInterstitialManager.mAdUnitId, Constants.SCENARIO_CHAPIN);
}
return;
}
......@@ -239,42 +229,31 @@ public class AdmobInterstitialManager {
AdData adData = CpAdData.getInstance().getAdData(CP_ADMOB);
if (adData == null) {
LLog.w(TAG, " adData = null");
if (null != adStatusCallBack) {
adStatusCallBack.nextMediaAppAdReq(Constants.NODE_NEXT_MEDIA_AD_REQ, AD_TYPE, "adData = null", -1, "", Constants.SCENARIO_CHAPIN);
}
return;
}
AdmobInterstitialManager.mAdUnitId = adData.getAdAdId(AdData.AD_TYPE_INTERSTITIAL, loadIndex);
if (TextUtils.isEmpty(AdmobInterstitialManager.mAdUnitId)) {
LLog.d(TAG, "loadAd admob chaping AdUnitId is empty loadIndex = "+loadIndex);
if (null != adStatusCallBack) {
adStatusCallBack.nextMediaAppAdReq(Constants.NODE_NEXT_MEDIA_AD_REQ, AD_TYPE, "AdUnitId is empty loadIndex = " + loadIndex, -1, "", Constants.SCENARIO_CHAPIN);
}
this.loadIndex = 0;
return;
}
if (isScreenLock(context)) {
LLog.d(TAG, "loadAd admob chaping 1.");
if (null != adStatusCallBack) {
adStatusCallBack.nextMediaAppAdReq(Constants.NODE_NEXT_MEDIA_AD_REQ, AD_TYPE, "isScreenLock", -2, AdmobInterstitialManager.mAdUnitId, Constants.SCENARIO_CHAPIN);
}
return;
}
if (!isScreenOn(context)) {
LLog.d(TAG, "loadAd admob chaping 2.");
if (null != adStatusCallBack) {
adStatusCallBack.nextMediaAppAdReq(Constants.NODE_NEXT_MEDIA_AD_REQ, AD_TYPE, "isScreenOff", -2, AdmobInterstitialManager.mAdUnitId, Constants.SCENARIO_CHAPIN);
}
return;
}
// if (!GoogleMobileAdsConsentManager.getInstance(context).canRequestAds()) {
if (!GoogleMobileAdsConsentManager.getInstance(context).canRequestAds()) {
// LLog.d(TAG, "loadAd admob chaping canRequestAds false.");
// if (null != adStatusCallBack) {
// adStatusCallBack.nextMediaAppAdReq(Constants.NODE_NEXT_MEDIA_AD_REQ, AD_TYPE, "canRequestAds false" , -1, AdmobInterstitialManager.mAdUnitId, Constants.SCENARIO_CHAPIN);
// }
try {
String country = CountryUtil.getLocalCountry(context);
StatsStaticHelper.onEvent("adC", country);
} catch (Exception e) {
}
// return;
// }
this.loadIndex = loadIndex + 1;
}
loadInterstitial(context, mAdUnitId);
} catch (Exception e) {
LLog.d(TAG, "loadAd chaping. e ----" + e.getMessage());
......
......@@ -9,7 +9,6 @@ import com.gem.media.InitA;
import java.util.HashMap;
public class CpAdData {
private static boolean isInit = false;
private static final class CpAdDataHolder {
static final CpAdData adManager = new CpAdData();
......@@ -19,11 +18,10 @@ public class CpAdData {
return CpAdDataHolder.adManager;
}
private static HashMap<String, AdData> adDataHashMap = new HashMap<>();
private HashMap<String, AdData> adDataHashMap;
public static final String CP_ADMOB = "admob";
public void setCpData(String cp, AdData adData) {
if (null == adDataHashMap) {
adDataHashMap = new HashMap<>();
......@@ -57,5 +55,4 @@ public class CpAdData {
}
}
}
package com.gem.media.splash.base.crash;
import android.util.Log;
import com.or.ange.dot.utils.LLog;
public class AESEncryptUtil {
private static final String sSecretKey = "b1ac9861485a652b";
private static final String iv = "1269571569321210";
public static byte[] encrypt2(String strToEncrypt) {
if (null == strToEncrypt) {
LLog.d("AESEncryptUtil: " , "strToEncrypt is null");
return new byte[0];
}
try {
return AesUtils.encryptString(sSecretKey, iv, strToEncrypt);
} catch (Exception e) {
LLog.d("AESEncryptUtil: " , e.toString());
}
return new byte[0];
}
public static String decrypt2(String strToDecrypt) {
if (null == strToDecrypt) {
LLog.d("AESEncryptUtil: " , "strToDecrypt is null");
return "";
}
try {
AesCodeC aesCodeC = new AesCodeC(iv, sSecretKey);
return aesCodeC.decode(strToDecrypt);
} catch (Throwable e) {
LLog.d("AESEncryptUtil: " , Log.getStackTraceString(e));
}
return "";
}
}
package com.gem.media.splash.base.crash;
import android.util.Base64;
public class AesCodeC{
private final String iv;
private final String key;
public AesCodeC(String iv, String key) {
this.iv = iv;
this.key = key;
}
public String decode(String encContent) throws Throwable {
return decryptContent(encContent);
}
private String decryptContent(String responseContent) throws Exception {
responseContent = trimEncryptContent(responseContent);
byte[] decode = Base64.decode(responseContent, Base64.NO_WRAP);
decode = AesUtils.decryptByte(key, iv, decode);
return new String(decode, "utf-8");
}
private String trimEncryptContent(String responseContent) {
if (responseContent.startsWith("\"")) {
responseContent = responseContent.substring(1);
}
if (responseContent.endsWith("\"")) {
responseContent = responseContent.substring(0, responseContent.length() - 1);
}
return responseContent;
}
}
package com.gem.media.splash.base.crash;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class AesUtils {
private static final String AES = "AES";
private static final String AES_CBC_PKCS5PADDING = "AES/CBC/PKCS5Padding";
public static byte[] encryptString(String key, String iv, String cleartext)
throws Exception {
return encryptByte(key, iv, cleartext.getBytes("utf-8"));
}
public static byte[] decryptByte(String key, String iv, byte[] encrypted)
throws Exception {
Cipher cipher = initAESCipher(key, iv, Cipher.DECRYPT_MODE);
return cipher.doFinal(encrypted);
}
public static byte[] encryptByte(String key, String iv, byte[] clear)
throws Exception {
Cipher cipher = initAESCipher(key, iv, Cipher.ENCRYPT_MODE);
return cipher.doFinal(clear);
}
public static Cipher initAESCipher(String key, String iv, int cipherMode)
throws Exception {
IvParameterSpec zeroIv = new IvParameterSpec(iv.getBytes("utf-8"));
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("utf-8"), AES);
Cipher cipher = Cipher.getInstance(AES_CBC_PKCS5PADDING);
cipher.init(cipherMode, skeySpec, zeroIv);
return cipher;
}
}
package com.gem.media.splash.base.crash;
import android.content.Context;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import java.util.Locale;
public final class CountryUtil {
private static final String TAG = "CountryUtil";
CountryUtil() {
}
public static String getCountryCode(Context context) {
String countryCode = "";
try {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
if (telephonyManager != null) {
countryCode = telephonyManager.getSimCountryIso();
if (countryCode != null && countryCode.length() == 2) {
return countryCode.toUpperCase(Locale.US);
}
if (telephonyManager.getPhoneType() != 2) {
countryCode = telephonyManager.getNetworkCountryIso();
if (countryCode != null && countryCode.length() == 2) {
return countryCode.toUpperCase(Locale.US);
}
}
}
} catch (Exception e) {
}
return countryCode;
}
public static String getSimCountryIso(Context context) {
String countryCode = "";
try {
countryCode = ((TelephonyManager) context.getSystemService("phone")).getSimCountryIso();
if (countryCode != null && countryCode.length() == 2) {
return countryCode.toUpperCase(Locale.US);
}
} catch (Exception e) {
}
return countryCode;
}
public static String getNetworkCountryIso(Context context) {
String countryCode = "";
try {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
if (telephonyManager.getPhoneType() != 2) {
countryCode = telephonyManager.getNetworkCountryIso();
if (countryCode != null && countryCode.length() == 2) {
return countryCode.toUpperCase(Locale.US);
}
}
} catch (Exception e) {
}
return countryCode;
}
public static String getLocalCountry(Context context) {
String countryCode = "";
try {
if (Build.VERSION.SDK_INT >= 24) {
countryCode = context.getResources().getConfiguration().getLocales().get(0).getCountry();
} else {
countryCode = context.getResources().getConfiguration().locale.getCountry();
}
} catch (Exception e) {
}
return countryCode;
}
public static String getSimOperatorMcc(Context context) {
try {
String operator = ((TelephonyManager) context.getApplicationContext().getSystemService("phone")).getSimOperator();
if (TextUtils.isEmpty(operator)) {
return "";
}
return operator.substring(0, 3);
} catch (Exception e) {
return "";
}
}
}
package com.gem.media.splash.base.crash;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.util.Log;
import com.gem.media.splash.base.utils.ALog;
import com.or.ange.dot.utils.ThreadManager;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class CrashHandler implements Thread.UncaughtExceptionHandler {
private static final String TAG = "CrashHandler";
private static final String DEX_EX = "dx_crs_ex";
private Thread.UncaughtExceptionHandler defUncaughtExceptionHandler;
private volatile boolean isInit = false;
private String appId;
private String appVersionName;
private String appVersionCode;
private String reportUrl;
private final CrashReportRunnable carshReportRunnable;
private static class Holder {
private static final CrashHandler INSTANCE = new CrashHandler();
}
private CrashHandler() {
carshReportRunnable = new CrashReportRunnable();
}
public static CrashHandler getInstance() {
return Holder.INSTANCE;
}
public void setup(Context context, String url, String appId) {
if (isInit) {
return;
}
isInit = true;
this.appId = appId;
appVersionName = getAppVersionName(context);
appVersionCode = getAppVersionCode(context);
this.reportUrl = url;
try {
defUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
} catch (Exception e) {
//
}
}
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
String exception = Log.getStackTraceString(throwable);
ALog.d(TAG, "exception---" + exception);
Map<String, String> map = new HashMap<>();
map.put("ex", exception);
Event event = generateEvent(DEX_EX, map);
carshReportRunnable.setEvent(event);
carshReportRunnable.setAppId(appId);
carshReportRunnable.setUrl(reportUrl);
ThreadManager.getNormalExecutor().submit(carshReportRunnable);
// defUncaughtExceptionHandler.uncaughtException(thread, throwable);
}
private Event generateEvent(String eventId, Map<String, String> params) {
Event event = new Event();
event.setEventId(eventId);
event.setVersionName(appVersionName);
event.setVersionCode(appVersionCode);
event.setTimestamp(System.currentTimeMillis());
if (params != null) {
event.setParams(new JSONObject(params).toString());
}
return event;
}
private static String getAppVersionName(Context context2) {
try {
PackageInfo pi = context2.getPackageManager().getPackageInfo(context2.getPackageName(), 0);
if (pi != null) {
return pi.versionName;
}
return "error:version";
} catch (Exception e) {
e.printStackTrace();
return "error:version";
}
}
private static String getAppVersionCode(Context context2) {
try {
PackageInfo pi = context2.getPackageManager().getPackageInfo(context2.getPackageName(), 0);
if (pi != null) {
return String.valueOf(pi.versionCode);
}
return "-1";
} catch (Exception e) {
e.printStackTrace();
return "-1";
}
}
}
package com.gem.media.splash.base.crash;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.os.Process;
import android.text.TextUtils;
import com.ads.cal.notes.BaseApplication;
import com.or.ange.dot.SystemUtils;
import com.or.ange.dot.utils.DeviceIDUtils;
import com.or.ange.dot.utils.LLog;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
public class CrashReportRunnable implements Runnable {
private static final String TAG = "ReportRunnable";
private JSONObject common;
private String imei;
private String androidId;
private String appId;
private String country;
private String language;
private String countryCode;
private String simOperatorMcc;
private volatile boolean isReporting = false;
private String reportUrl;
private Event event;
public CrashReportRunnable() {
Context context = BaseApplication.getApplication();
try {
this.imei = DeviceIDUtils.getImei(context);
this.androidId = SystemUtils.getAndroidId(context);
this.country = Locale.getDefault().getCountry();
this.language = Locale.getDefault().getLanguage();
} catch (Exception e2) {
}
try {
this.countryCode = CountryUtil.getCountryCode(context);
this.simOperatorMcc = CountryUtil.getSimOperatorMcc(context);
} catch (Exception e3) {
}
}
public void setEvent(Event event) {
this.event = event;
}
public void setUrl(String reportUrl) {
this.reportUrl = reportUrl;
}
public void setAppId(String appId) {
this.appId = appId;
}
@Override
public void run() {
List<Event> events = new ArrayList<>();
if (event != null) {
events.add(event);
}
if (events.isEmpty()) {
LLog.d(TAG, "events is empty, not report.");
return;
}
boolean success = false;
this.isReporting = true;
BufferedReader br = null;
try {
JSONObject object = getTrackerJSONObject(events);
HashMap<String, String> heads = new HashMap<>();
heads.put("Content-Type", "application/json");
HttpURLConnection conn = Http.post(reportUrl, heads, null, object.toString());
if (conn != null) {
success = conn.getResponseCode() == 200;
if (success) {
StringBuilder rest = new StringBuilder();
br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
while (true) {
String line = br.readLine();
if (null == line) {
break;
}
rest.append(line);
}
success = new JSONObject(AESEncryptUtil.decrypt2(rest.toString())).optInt("a") == 0;
}
}
if (br != null) {
try {
br.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
if (success) {
LLog.d(TAG, "track after success ");
} else {
if (conn == null) {
LLog.d(TAG, "track fail. null" );
} else {
LLog.d(TAG, "track fail. code = " + conn.getResponseCode());
}
}
this.isReporting = false;
} catch (Exception e) {
if (br != null) {
try {
br.close();
} catch (Exception e22) {
this.isReporting = false;
}
}
if (!success) {
}
this.isReporting = false;
} catch (Throwable th) {
if (br != null) {
try {
br.close();
} catch (Exception e23) {
e23.printStackTrace();
throw th;
}
}
if (!success) {
}
this.isReporting = false;
throw th;
} finally {
LLog.d(TAG, " Process.killProcess "+Process.myPid());
Process.killProcess(Process.myPid());
}
}
private JSONObject getTrackerJSONObject(List<Event> events) {
JSONObject object = new JSONObject();
try {
object.put("cp", getCommonJSONObject());
JSONArray array = new JSONArray();
for (Event event : events) {
array.put(getEventJSONObject(event));
}
object.put("e", array);
object.put("n", "1");
} catch (JSONException e) {
LLog.d(TAG, e.toString());
}
return object;
}
@SuppressLint({"MissingPermission"})
private JSONObject getCommonJSONObject() throws JSONException {
Context context = BaseApplication.getApplication();
if (this.common == null && null != context) {
String pkgName = context.getPackageName();
this.common = new JSONObject();
this.common.put("ai", this.appId);
this.common.put("i", this.imei);
this.common.put("a_id", this.androidId);
this.common.put("pk", pkgName);
this.common.put("vc", getAppVersionCode());
this.common.put("vn", getAppVersionName());
this.common.put("ol", Build.VERSION.SDK_INT);
this.common.put("ov", Build.VERSION.RELEASE);
this.common.put("b", Build.BRAND);
this.common.put("m", Build.MODEL);
this.common.put("d", Build.DEVICE);
this.common.put("bo", Build.BOARD);
this.common.put("ft", Build.FINGERPRINT);
this.common.put("hw", Build.HARDWARE);
this.common.put("dy", Build.DISPLAY);
this.common.put("id", Build.ID);
this.common.put("pt", Build.PRODUCT);
this.common.put("us", Build.USER);
this.common.put("mf", Build.MANUFACTURER);
this.common.put("cn", this.country);
this.common.put("lag", this.language);
this.common.put("coc", this.countryCode);
this.common.put("som", this.simOperatorMcc);
if (Build.VERSION.SDK_INT >= 26) {
String serial = "";
try {
serial = Build.getSerial();
} catch (Exception e) {
}
this.common.put("sn", serial);
}
}
return this.common;
}
private JSONObject getEventJSONObject(Event event) throws JSONException {
JSONObject object = new JSONObject();
object.put("ei", event.getEventId());
if (!BaseApplication.getApplication().getPackageName().equals(event.getLabel())) {
object.put("label", event.getLabel());
}
object.put("et", event.getTimestamp());
if (!getAppVersionName().equals(event.getVersionName())) {
object.put("vc", event.getVersionCode());
object.put("vn", event.getVersionName());
}
if (!TextUtils.isEmpty(event.getParams())) {
object.put("pm", new JSONObject(event.getParams()));
}
return object;
}
public boolean isReporting() {
return this.isReporting;
}
private static String getAppVersionName() {
try {
Context context = BaseApplication.getApplication();
PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
if (pi != null) {
return pi.versionName;
}
return "error:version";
} catch (Exception e) {
e.printStackTrace();
return "error:version";
}
}
private String getAppVersionCode() {
try {
Context context = BaseApplication.getApplication();
PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
if (pi != null) {
return String.valueOf(pi.versionCode);
}
return "-1";
} catch (Exception e) {
e.printStackTrace();
return "-1";
}
}
}
package com.gem.media.splash.base.crash;
public class Event {
private int id;
private String eventId;
private String label;
private String versionName;
private String versionCode;
private long timestamp;
private String params;
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getEventId() {
return this.eventId;
}
public void setEventId(String eventId) {
this.eventId = eventId;
}
public String getLabel() {
return this.label;
}
public void setLabel(String label) {
this.label = label;
}
public String getVersionName() {
return this.versionName;
}
public void setVersionName(String versionName) {
this.versionName = versionName;
}
public String getVersionCode() {
return this.versionCode;
}
public void setVersionCode(String versionCode) {
this.versionCode = versionCode;
}
public long getTimestamp() {
return this.timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public String getParams() {
return this.params;
}
public void setParams(String params) {
this.params = params;
}
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Event event = (Event) o;
if (this.timestamp != event.timestamp) {
return false;
}
return this.eventId.equals(event.eventId);
}
public int hashCode() {
return (31 * this.eventId.hashCode()) + ((int) (this.timestamp ^ (this.timestamp >>> 32)));
}
public String toString() {
return "Event(id='" + this.id + "', eventId='" + this.eventId + "', label='" + this.label + "', vn='" + this.versionName + "', vc='" + this.versionCode + "', params='" + this.params + "')";
}
}
package com.gem.media.splash.base.crash;
import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.util.Base64;
import com.or.ange.dot.utils.LLog;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.Map;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class Http {
private static final String TAG = "DotHttp";
private Http() {
throw new UnsupportedOperationException();
}
private static void setHttpsFactory(HttpURLConnection conn) {
if (conn instanceof HttpsURLConnection) {
HttpsURLConnection httpsConn = (HttpsURLConnection)conn;
httpsConn.setHostnameVerifier(new SkipHostnameVerifier());
try {
httpsConn.setSSLSocketFactory(createSslSocketFactory());
} catch (Exception var3) {
var3.printStackTrace();
}
}
}
public static HttpURLConnection post(String uri, Map<String, String> heads, Map<String, String> params, String body) throws IOException {
URL url;
if (params != null && params.size() > 0) {
url = new URL(uri + "?" + convertRequestParamsToString(params));
} else {
url = new URL(uri);
}
OutputStream outputStream = null;
while(true) {
try {
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setAllowUserInteraction(false);
conn.setConnectTimeout(20000);
conn.setReadTimeout(20000);
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/octet-stream");
conn.setRequestProperty("e", "5");
setHttpsFactory(conn);
if (!TextUtils.isEmpty(body)) {
String encryptBody = Base64.encodeToString(AESEncryptUtil.encrypt2(body), Base64.NO_WRAP);
outputStream = conn.getOutputStream();
outputStream.write((encryptBody).getBytes("UTF-8"));
outputStream.flush();
}
int responseCode = conn.getResponseCode();
LLog.d(TAG, "responseCode "+responseCode);
switch (responseCode) {
case 200:
case 206:
HttpURLConnection var25 = conn;
return var25;
case 301:
case 302:
case 303:
case 307:
String location = conn.getHeaderField("Location");
url = new URL(location);
break;
case 416:
throw new StopRequestException(416);
default:
return null;
}
} catch (Exception var21) {
return null;
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException var20) {
}
}
}
}
}
public static String convertRequestParamsToString(Map<String, String> params) throws IOException {
StringBuilder result = new StringBuilder();
boolean first = true;
for (String key : params.keySet()) {
String value = params.get(key);
if (!TextUtils.isEmpty(value)) {
if (first) {
first = false;
} else {
result.append("&");
}
result.append(URLEncoder.encode(key, "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(value, "UTF-8"));
}
}
return result.toString();
}
private static SSLSocketFactory createSslSocketFactory() throws Exception {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new TrustManager[]{new SkipX509TrustManager()}, new SecureRandom());
return context.getSocketFactory();
}
public static class StopRequestException extends RuntimeException {
private final int code;
public StopRequestException(int code) {
this.code = code;
}
public int getCode() {
return this.code;
}
}
private static class SkipHostnameVerifier implements HostnameVerifier {
private SkipHostnameVerifier() {
}
@SuppressLint({"BadHostnameVerifier"})
public boolean verify(String s, SSLSession sslSession) {
return true;
}
}
private static class SkipX509TrustManager implements X509TrustManager {
private SkipX509TrustManager() {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
@SuppressLint({"TrustAllX509TrustManager"})
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
@SuppressLint({"TrustAllX509TrustManager"})
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
}
}
/*
* Tencent is pleased to support the open source community by making wechat-matrix available.
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gem.media.splash.base.matrix;
public enum MatrixEnum {
/*****matrix begin********/
// trace
clicfg_matrix_trace_fps_enable,
clicfg_matrix_trace_care_scene_set,
clicfg_matrix_trace_fps_time_slice,
clicfg_matrix_trace_load_activity_threshold,
clicfg_matrix_trace_evil_method_threshold,
clicfg_matrix_trace_fps_report_threshold,
clicfg_matrix_trace_max_evil_method_stack_num,
clicfg_matrix_trace_max_evil_method_try_trim_num,
clicfg_matrix_trace_min_evil_method_druration,
clicfg_matrix_trace_time_upload_duration,
clicfg_matrix_fps_dropped_normal,
clicfg_matrix_fps_dropped_middle,
clicfg_matrix_fps_dropped_high,
clicfg_matrix_fps_dropped_frozen,
clicfg_matrix_trace_evil_method_enable,
clicfg_matrix_trace_startup_enable,
clicfg_matrix_trace_app_start_up_threshold,
clicfg_matrix_trace_fps_frame_fresh_threshold,
clicfg_matrix_trace_min_evil_method_run_cnt,
clicfg_matrix_trace_min_evil_method_dur_time,
clicfg_matrix_trace_splash_activity_name,
//io
clicfg_matrix_io_file_io_main_thread_enable,
clicfg_matrix_io_main_thread_enable_threshold,
clicfg_matrix_io_small_buffer_enable,
clicfg_matrix_io_small_buffer_threshold,
clicfg_matrix_io_small_buffer_operator_times,
clicfg_matrix_io_repeated_read_enable,
clicfg_matrix_io_repeated_read_threshold,
clicfg_matrix_io_closeable_leak_enable,
//resource
clicfg_matrix_resource_detect_interval_millis,
clicfg_matrix_resource_max_detect_times,
clicfg_matrix_resource_dump_hprof_enable,
/******matrix end*******/
}
package com.gem.media.splash.base.matrix;
import android.app.Application;
import android.util.Log;
import com.gem.media.splash.base.utils.ALog;
import com.tencent.matrix.Matrix;
import com.tencent.matrix.trace.TracePlugin;
import com.tencent.matrix.trace.config.TraceConfig;
public class MatrixUtils {
private static final String TAG = "MatrixUtils";
public static void init(Application application) {
try {
MdDynamicConfigImpl dynamicConfig = new MdDynamicConfigImpl();
ALog.d(TAG, "Start Matrix configurations start ");
// Builder. Not necessary while some plugins can be configured separately.
Matrix.Builder builder = new Matrix.Builder(application);
builder.pluginListener(new MdPluginListener(application));
TracePlugin tracePlugin = configureTracePlugin(dynamicConfig);
builder.plugin(tracePlugin);
Matrix.init(builder.build());
tracePlugin.start();
ALog.d(TAG, "Start Matrix configurations end ");
} catch (Exception e) {
ALog.e(TAG, "matrix init e :" + Log.getStackTraceString(e));
}
}
private static TracePlugin configureTracePlugin(MdDynamicConfigImpl dynamicConfig) {
boolean fpsEnable = dynamicConfig.isFPSEnable();
boolean traceEnable = dynamicConfig.isTraceEnable();
boolean signalAnrTraceEnable = dynamicConfig.isSignalAnrTraceEnable();
ALog.d(TAG, "fpsEnable :" + fpsEnable + ",,traceEnable :" + traceEnable
+ ", signalAnrTraceEnable :" + signalAnrTraceEnable);
TraceConfig traceConfig = new TraceConfig.Builder()
.dynamicConfig(dynamicConfig)
.enableAnrTrace(traceEnable)
.enableSignalAnrTrace(signalAnrTraceEnable) // Introduced in Matrix 2.0
.enableEvilMethodTrace(false)
.isDebug(false)
.isDevEnv(false)
.build();
return new TracePlugin(traceConfig);
}
}
/*
* Tencent is pleased to support the open source community by making wechat-matrix available.
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gem.media.splash.base.matrix;
import com.tencent.mrs.plugin.IDynamicConfig;
public class MdDynamicConfigImpl implements IDynamicConfig {
private static final String TAG = "Matrix.MdDynamicConfigImpl";
public MdDynamicConfigImpl() {
}
public boolean isFPSEnable() {
return false;
}
public boolean isTraceEnable() {
return true;
}
public boolean isSignalAnrTraceEnable() {
return true;
}
public boolean isMatrixEnable() {
return true;
}
@Override
public String get(String key, String defStr) {
return defStr;
}
@Override
public int get(String key, int defInt) {
//TODO here return default value which is inside sdk, you can change it as you wish. matrix-sdk-key in class MatrixEnum.
if (MatrixEnum.clicfg_matrix_trace_fps_report_threshold.name().equals(key)) {
return 10000;
}
if (MatrixEnum.clicfg_matrix_trace_fps_time_slice.name().equals(key)) {
return 12000;
}
return defInt;
}
@Override
public long get(String key, long defLong) {
//TODO here return default value which is inside sdk, you can change it as you wish. matrix-sdk-key in class MatrixEnum.
if (MatrixEnum.clicfg_matrix_trace_fps_report_threshold.name().equals(key)) {
return 10000L;
}
return defLong;
}
@Override
public boolean get(String key, boolean defBool) {
//TODO here return default value which is inside sdk, you can change it as you wish. matrix-sdk-key in class MatrixEnum.
return defBool;
}
@Override
public float get(String key, float defFloat) {
//TODO here return default value which is inside sdk, you can change it as you wish. matrix-sdk-key in class MatrixEnum.
return defFloat;
}
}
/*
* Tencent is pleased to support the open source community by making wechat-matrix available.
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gem.media.splash.base.matrix;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.Process;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.NonNull;
import com.gem.media.StatsStaticHelper;
import com.gem.media.splash.base.utils.ALog;
import com.tencent.matrix.plugin.DefaultPluginListener;
import com.tencent.matrix.report.Issue;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MdPluginListener extends DefaultPluginListener {
public static final String TAG = "MdPluginListener";
private static final String EVENT_ANR_EXCEPTION = "anr_ex";
private static final int MSG_CHECK_REAL_ANR = 1;
private static final int CHECK_ERROR_STATE_INTERVAL = 500;
private static final int ANR_DUMP_MAX_TIME = 20000;
private static final int CHECK_ERROR_STATE_COUNT = ANR_DUMP_MAX_TIME / CHECK_ERROR_STATE_INTERVAL;
private Context context;
private Handler anrCheckHandler;
private HandlerThread handlerThread;
private volatile int checkNum = 0;
public MdPluginListener(Context context) {
super(context);
this.context = context;
}
private void initHandle() {
handlerThread = new HandlerThread("mtx_ar_t");
handlerThread.start();
anrCheckHandler = new Handler(handlerThread.getLooper()) {
@Override
public void handleMessage(@NonNull Message msg) {
switch (msg.what) {
case MSG_CHECK_REAL_ANR:
try {
boolean myAnr = checkErrorState();
// ALog.d(TAG, " myAnr :" + myAnr + ", checkNum :" + checkNum);
if (myAnr) {
ALog.d(TAG, "real anr occur !");
Process.killProcess(Process.myPid());
break;
}
ALog.d(TAG, " ---not anr ----" + ", checkNum :" + checkNum);
} catch (Throwable e) {
ALog.e(TAG, "myAnr e : " + Log.getStackTraceString(e));
} finally {
checkNum++;
ALog.d(TAG, "finally checkNum: " + checkNum + ",,max :" + CHECK_ERROR_STATE_COUNT);
if (checkNum < CHECK_ERROR_STATE_COUNT && anrCheckHandler != null) {
try {
Message message = Message.obtain();
message.what = MSG_CHECK_REAL_ANR;
message.arg1 = checkNum;
anrCheckHandler.sendMessageDelayed(message, CHECK_ERROR_STATE_INTERVAL);
} catch (Exception e) {
destroyHandler();
}
} else {
ALog.d(TAG, "destroyHandler");
destroyHandler();
}
}
break;
}
}
};
}
private void destroyHandler() {
try {
if (handlerThread != null) {
handlerThread.quitSafely();
}
} catch (Exception e) {
}
handlerThread = null;
anrCheckHandler = null;
checkNum = 0;
}
@Override
public void onReportIssue(final Issue issue) {
super.onReportIssue(issue);
// ALog.d(TAG, " issue :" + issue);
checkANRHappened(issue);
}
private void checkANRHappened(Issue issue) {
if (issue == null) {
return;
}
try {
JSONObject content = issue.getContent();
if (content == null) {
return;
}
String type = content.getString("detail");
ALog.d(TAG, " issue type :" + type);
if (!TextUtils.isEmpty(type) && type.contains("ANR")) {
ALog.d(TAG, "check anr !");
statAnr(type);
if (anrCheckHandler == null) {
initHandle();
}
Message message = Message.obtain();
message.what = MSG_CHECK_REAL_ANR;
message.arg1 = checkNum;
anrCheckHandler.sendMessageDelayed(message, CHECK_ERROR_STATE_INTERVAL);
}
} catch (Exception e) {
}
// ALog.d(TAG, " isAnrMsg :" + isAnrMsg);
/* if (!isAnrMsg) {
return;
}*/
/* new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 40; i++) {
try {
boolean myAnr = checkErrorState();
ALog.d(TAG, " myAnr :" + myAnr + ", i :" + i);
if (myAnr) {
Process.killProcess(Process.myPid());
break;
}
ALog.d(TAG, " -------" + ", i :" + i);
Thread.sleep(500);
} catch (Throwable e) {
ALog.e(TAG, "myAnr e : " + Log.getStackTraceString(e));
break;
}
}
}
}).start();*/
}
private boolean checkErrorState() {
try {
ALog.i(TAG, "[checkErrorState] start");
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.ProcessErrorStateInfo> procs = am.getProcessesInErrorState();
if (procs == null) {
ALog.i(TAG, "[checkErrorState] procs == null");
return false;
}
for (ActivityManager.ProcessErrorStateInfo proc : procs) {
ALog.i(TAG, "[checkErrorState] found Error State proccessName = "+ proc.processName + ", proc.condition = " + proc.condition);
if (proc.uid != Process.myUid()
&& proc.condition == ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING) {
ALog.i(TAG, "maybe received other apps ANR signal");
return false;
}
if (proc.pid != Process.myPid()) continue;
if (proc.condition != ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING) {
continue;
}
ALog.i(TAG, "error sate proc.condition =" + proc.condition);
return true;
}
return false;
} catch (Throwable t) {
ALog.e(TAG, "[checkErrorState] error : %s", t.getMessage());
}
return false;
}
private void statAnr(String type) {
try {
Map<String, String> map = new HashMap<>();
map.put("type", type);
StatsStaticHelper.reportOnEvent(EVENT_ANR_EXCEPTION, null, map);
} catch (Exception e) {
}
}
}
......@@ -6,15 +6,10 @@ public class Constants {
public static final String NODE_REQUEST_SUCCESS_EID = "ad_req_dur_eid"; // 广告请求成功
public static final String NODE_SHOW_EID = "ad_exp_eid"; // 广告展示
public static final String NODE_CLICK_EID = "ad_clk_eid"; // 广告点击
public static final String NODE_OPEN_EID = "ad_open_eid"; // 广告点击
public static final String NODE_CLOSE_EID = "ad_close_eid"; // 广告关闭
public static final String NODE_ERROR_EID = "ad_faile_eid"; //广告错误
public static final String NODE_NEXT_MEDIA_AD_REQ = "next_media_ad_req"; //admob全屏广告显示错误
public static final String NODE_FAILED_TO_SHOW_EID = "ad_failed_to_show_eid"; //admob全屏广告显示错误
public static final String NODE_FAILED_TO_SHOW = "ad_failed_to_show"; //admob全屏广告显示错误
public static final String NODE_CLEAR_PAGE_SHOW = "cleanHomePageShow";
public static final String NODE_CLEAR_PAGE_SHOW_TIME = "CleanPageTime";
public static final String NODE_OPEN_EID = "ad_open_eid"; // 广告点击
public static final String NODE_OPEN = "ad_open"; // 广告
public static final String NODE_REQUEST = "ad_req"; // 广告请求
......@@ -26,14 +21,21 @@ public class Constants {
public static final String NODE_CLICK = "ad_clk"; // 广告点击
public static final String NODE_CLOSE = "ad_close"; // 广告关闭
public static final String NODE_ERROR = "ad_faile"; //广告错误
public static final String NODE_OPEN = "ad_open"; // 广告
public static final String NODE_CACHE = "ad_has_cache";//广告有缓存
public static final String NODE_CACHE_D = "ad_has_cache_d";//广告有缓存
public static final String NODE_FAILED_TO_SHOW = "ad_failed_to_show"; //admob全屏广告显示错误
public static final String NODE_NEXT_MEDIA_AD_REQ = "next_media_ad_req"; //admob全屏广告显示错误
public static final String NODE_PAGE_SHOW = "PAGE_SHOW";
public static final String NODE_AD_REQ_NET = "ad_req_net";//请求广告有网络
public static final String NODE_AD_NOT_INIT = "ad_not_init";//广告未初始化
public static final String NODE_AD_REQ_NOT_NET = "ad_req_n_net";//请求广告无网络
public static final String NODE_AD_REQ_STATUS = "ad_req_status";//广告去请求状态
public static final String MEDIA_APP_START = "media_start";
public static final String NODE_CLEAR_PAGE_SHOW = "cleanHomePageShow";
public static final String NODE_CLEAR_PAGE_RESULT_SHOW = "CLEAR_PAGE_RESULT_SHOW";
public static final String NODE_CLEAR_PAGE_SHOW_TIME = "CleanPageTime";
public static final String NODE_CLEAR_PAGE_SHOW_FAIL = "CLEAR_PAGE_SHOW_FAIL";
public static final String NODE_INTERSTITIAL_AD_VIDEO_START = "INTERSTITIAL_AD_VIDEO_START";
......@@ -43,7 +45,6 @@ public class Constants {
public static final String NODE_INTERSTITIAL_AD_VIDEO_ERROR = "INTERSTITIAL_AD_VIDEO_ERROR";
public static final String NODE_NATIVE_AD_VIDEO_START = "NATIVE_AD_VIDEO_START";
public static final String NODE_NATIVE_AD_VIDEO_END = "NATIVE_AD_VIDEO_END";
......@@ -54,30 +55,25 @@ public class Constants {
public static final String PROCESS_RESTART_AD_REQ_CALLBACK = "p_r_c";//媒体app去请求广告后APP重启事件
//H5页面展示时常参数是t
public static final String H_SHOW_TIME = "h_time";
//H5页面开始加载参数是url
public static final String H_PAGE_START = "h_p_s";
//H5页面加载完成参数是url
public static final String H_PAGE_FINISH = "h_p_f";
//H5页面加载失败参数是url 和 r
public static final String H_PAGE_ERROR = "h_p_e";
//H5页面搜索关键字参数是text
public static final String H_PAGE_SEARCH_TEXT = "h_p_st";
public static final String H_CREATE = "h_c";
public static final String N_RELOAD = "n_reload";//启动原生广告页面没有广告缓存重新加载
public static final String N_REMOVE = "n_r";//
public static final String N_CREATE = "n_c";//去启动原生广告页面
public static final String N_WM_NOT_PER = "wm_not_per_n";
public static final String N_WM_PER = "wm_per_n";
public static final String WM_NOT_PER = "wm_not_per";
public static final String WM_PER = "wm_per";
public static final String SCENARIO_1 = "chapin";
public static final String SCENARIO_2 = "yuansheng";
public static final String SCENARIO_3 = "kaipin";
public static final String SCENARIO_4 = "admob_chapin";
public static final String MEDIA_APP_START = "media_start";
public static final String START_GP_LIVE = "startGpLive";
public static final String AD_INIT_S = "m_init_s";
public static final String AD_INIT_F = "m_init_f";
public static final String START_LIVE = "startLive";
public static final String PARAM_ADID = "adId";
public static final String PARAM_PID = "pid";
public static final String PARAM_TYPE = "type";
public static final String PARAM_AD_TYPE = "ad_type";
......
......@@ -7,6 +7,7 @@ import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.Window;
import android.view.WindowManager;
......@@ -14,8 +15,15 @@ import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
public class BarUtils {
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/09/23
* desc : utils about bar
* </pre>
*/
public final class BarUtils {
///////////////////////////////////////////////////////////////////////////
// status bar
......@@ -40,36 +48,6 @@ public class BarUtils {
return resources.getDimensionPixelSize(resourceId);
}
/**
* Set the status bar's visibility.
*
* @param activity The activity.
* @param isVisible True to set status bar visible, false otherwise.
*/
public static void setStatusBarVisibility(@NonNull final Activity activity,
final boolean isVisible) {
setStatusBarVisibility(activity.getWindow(), isVisible);
}
/**
* Set the status bar's visibility.
*
* @param window The window.
* @param isVisible True to set status bar visible, false otherwise.
*/
public static void setStatusBarVisibility(@NonNull final Window window,
final boolean isVisible) {
if (isVisible) {
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
showStatusBarView(window);
addMarginTopEqualStatusBarHeight(window);
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
hideStatusBarView(window);
subtractMarginTopEqualStatusBarHeight(window);
}
}
/**
* Return whether the status bar is visible.
*
......@@ -147,7 +125,7 @@ public class BarUtils {
view.setTag(TAG_OFFSET);
Object haveSetOffset = view.getTag(KEY_OFFSET);
if (haveSetOffset != null && (Boolean) haveSetOffset) return;
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
MarginLayoutParams layoutParams = (MarginLayoutParams) view.getLayoutParams();
layoutParams.setMargins(layoutParams.leftMargin,
layoutParams.topMargin + getStatusBarHeight(),
layoutParams.rightMargin,
......@@ -164,7 +142,7 @@ public class BarUtils {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
Object haveSetOffset = view.getTag(KEY_OFFSET);
if (haveSetOffset == null || !(Boolean) haveSetOffset) return;
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
MarginLayoutParams layoutParams = (MarginLayoutParams) view.getLayoutParams();
layoutParams.setMargins(layoutParams.leftMargin,
layoutParams.topMargin - getStatusBarHeight(),
layoutParams.rightMargin,
......@@ -186,32 +164,6 @@ public class BarUtils {
subtractMarginTopEqualStatusBarHeight(withTag);
}
/**
* Set the status bar's color.
*
* @param activity The activity.
* @param color The status bar's color.
*/
public static View setStatusBarColor(@NonNull final Activity activity,
@ColorInt final int color) {
return setStatusBarColor(activity, color, false);
}
/**
* Set the status bar's color.
*
* @param activity The activity.
* @param color The status bar's color.
* @param isDecor True to add fake status bar in DecorView,
* false to add fake status bar in ContentView.
*/
public static View setStatusBarColor(@NonNull final Activity activity,
@ColorInt final int color,
final boolean isDecor) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return null;
transparentStatusBar(activity);
return applyStatusBarColor(activity, color, isDecor);
}
/**
......@@ -314,10 +266,6 @@ public class BarUtils {
}
}
///////////////////////////////////////////////////////////////////////////
// action bar
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// navigation bar
......@@ -385,7 +333,6 @@ public class BarUtils {
}
/**
* Set the nav bar's light mode.
*
......@@ -447,7 +394,7 @@ public class BarUtils {
}
public static void transparentNavBar(@NonNull final Window window) {
if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.setNavigationBarContrastEnforced(false);
}
......@@ -463,5 +410,4 @@ public class BarUtils {
int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(vis | option);
}
}
\ No newline at end of file
package com.gem.media.util;
import static android.media.AudioManager.AUDIOFOCUS_REQUEST_FAILED;
import android.content.Context;
import android.media.AudioFocusRequest;
import android.media.AudioManager;
import android.os.Build;
import android.telephony.TelephonyManager;
import com.gem.media.splash.base.utils.ALog;
public class CAudioManagerUtils {
private static final String TAG = "CAudioManagerUtils";
private static final class CAudioManagerUtilsHolder {
private static final CAudioManagerUtils manager = new CAudioManagerUtils();
}
public static CAudioManagerUtils getInstance() {
return CAudioManagerUtilsHolder.manager;
}
private AudioManager mAudioManager;
public AudioManager getAudioManager(Context context) {
if (mAudioManager == null) {
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
}
return mAudioManager;
}
private boolean isInCalling(Context context) {
int mode = getAudioManager(context).getMode();
return mode == AudioManager.MODE_IN_CALL || mode == AudioManager.MODE_IN_COMMUNICATION;
}
public boolean isCalling(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int callState = telephonyManager.getCallState();
return callState != TelephonyManager.CALL_STATE_IDLE || isInCalling(context);
}
private final AudioManager.OnAudioFocusChangeListener afChangeListener = focusChange -> {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_LOSS:
ALog.e(TAG, "AudioManager.AUDIOFOCUS_LOSS = ");
// 长时间失去焦点,应当停止播放并释放资源
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
ALog.e(TAG, "AudioManager.AUDIOFOCUS_LOSS_TRANSIENT = ");
// 短暂失去焦点,暂停播放等待焦点恢复
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
ALog.e(TAG, "AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK = ");
// 短暂失去焦点,可降低音量继续播放(“鸭子式”处理)
break;
case AudioManager.AUDIOFOCUS_GAIN:
ALog.e(TAG, "AudioManager.AUDIOFOCUS_GAIN = ");
// 获得焦点,恢复播放
break;
}
};
private AudioFocusRequest audioFocusRequest;
public boolean isRequestAudioFocus(Context context) {
boolean b = isCalling(context);
ALog.e(TAG, "iscalling = " + b);
if (b) {
return true;
}
int result;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AudioFocusRequest.Builder builder = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN);
builder.setOnAudioFocusChangeListener(afChangeListener);
audioFocusRequest = builder.build();
result = getAudioManager(context).requestAudioFocus(audioFocusRequest);
} else {
result = getAudioManager(context).requestAudioFocus(afChangeListener,
AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN);
}
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
ALog.e(TAG, "获得音频焦点");
} else if (result == AUDIOFOCUS_REQUEST_FAILED) {
ALog.e(TAG, "没有获得音频焦点");
} else {
ALog.e(TAG, "result " + result);
}
return false;
}
public void cancelAudioFocus(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (null != audioFocusRequest) {
getAudioManager(context).abandonAudioFocusRequest(audioFocusRequest);
audioFocusRequest= null;
mAudioManager = null;
ALog.e(TAG, "abandonAudioFocusRequest");
}
} else {
getAudioManager(context).abandonAudioFocus(afChangeListener);
ALog.e(TAG, "abandonAudioFocus");
}
}
}
package com.gem.media.util;
import com.gem.media.RestartAndOnlineTimeStaticsHelper;
public class GKpLiveHelper {
private static final class KpLiveHelperHolder {
private static final GKpLiveHelper kpLiveUtil = new GKpLiveHelper();
}
public static GKpLiveHelper getInstance() {
return KpLiveHelperHolder.kpLiveUtil;
}
private long initTime = 0L;
public void init() {
if (initTime == 0L) {
initTime = System.currentTimeMillis();
} else {
long currentTime = System.currentTimeMillis();
int minute = (int) ((currentTime - initTime) / 60);
initTime = currentTime;
RestartAndOnlineTimeStaticsHelper.checkOnLineTime(minute);
}
}
}
package com.gem.media.util;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
......
This diff is collapsed.
This diff is collapsed.
......@@ -34,4 +34,5 @@ dependencyResolutionManagement {
rootProject.name = "Notes"
include ':app'
include ':admob_media_app'
include ':admob_gp_media_app'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment