|
@@ -5,7 +5,6 @@ import android.app.Activity;
|
|
|
import android.app.Application;
|
|
|
import android.content.Context;
|
|
|
import android.content.DialogInterface;
|
|
|
-import android.content.SharedPreferences;
|
|
|
import android.os.Build;
|
|
|
import android.provider.Settings;
|
|
|
import android.telephony.TelephonyManager;
|
|
@@ -14,24 +13,27 @@ import android.text.TextUtils;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
+import java.lang.reflect.Constructor;
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
import cn.yyxx.commsdk.base.entity.ResultInfo;
|
|
|
import cn.yyxx.commsdk.base.internal.ICallback;
|
|
|
+import cn.yyxx.commsdk.base.internal.IMsaDeviceCallback;
|
|
|
import cn.yyxx.commsdk.base.internal.IRequestCallback;
|
|
|
import cn.yyxx.commsdk.base.utils.Logger;
|
|
|
import cn.yyxx.commsdk.core.SdkDrive;
|
|
|
import cn.yyxx.commsdk.core.constants.Constants;
|
|
|
+import cn.yyxx.commsdk.core.entry.bean.InitBean;
|
|
|
import cn.yyxx.commsdk.core.network.SdkRequest;
|
|
|
import cn.yyxx.commsdk.core.ui.dialog.PrivacyPolicyDialog;
|
|
|
import cn.yyxx.commsdk.core.ui.dialog.SingleButtonDialog;
|
|
|
+import cn.yyxx.commsdk.core.utils.MMKVUtils;
|
|
|
import cn.yyxx.commsdk.core.utils.ManifestUtils;
|
|
|
import cn.yyxx.commsdk.core.utils.ParamsUtils;
|
|
|
import cn.yyxx.commsdk.core.utils.ResourceUtil;
|
|
|
-import cn.yyxx.commsdk.core.utils.SharedPreferencesUtils;
|
|
|
-import cn.yyxx.commsdk.impl.channel.msa.IMsaDeviceIdsCallback;
|
|
|
-import cn.yyxx.commsdk.impl.channel.msa.MsaDeviceIdsHandler;
|
|
|
import cn.yyxx.support.JsonUtils;
|
|
|
|
|
|
import cn.yyxx.support.permission.IPermissionCallback;
|
|
@@ -39,17 +41,20 @@ import cn.yyxx.support.permission.Permission;
|
|
|
import cn.yyxx.support.permission.PermissionKit;
|
|
|
|
|
|
public class CommonOperationManager {
|
|
|
- public static CommonOperationManager permissionManager = null;
|
|
|
+ public static CommonOperationManager commonOperationManager = null;
|
|
|
|
|
|
private boolean hasIdsRead = false;
|
|
|
+ private String oaid = "";
|
|
|
|
|
|
|
|
|
+ public static InitBean initBean = null;
|
|
|
+
|
|
|
private CommonOperationManager(){}
|
|
|
public static CommonOperationManager getInstance(){
|
|
|
- if (permissionManager == null){
|
|
|
- permissionManager = new CommonOperationManager();
|
|
|
+ if (commonOperationManager == null){
|
|
|
+ commonOperationManager = new CommonOperationManager();
|
|
|
}
|
|
|
- return permissionManager;
|
|
|
+ return commonOperationManager;
|
|
|
}
|
|
|
public void initAgreement(Activity activity, ICallback callback){
|
|
|
|
|
@@ -68,8 +73,7 @@ public class CommonOperationManager {
|
|
|
}
|
|
|
|
|
|
|
|
|
- String isShowPolicy = SharedPreferencesUtils.getSharedPreferences(activity, Constants.SP_KEY,"isShowPolicy");
|
|
|
-
|
|
|
+ String isShowPolicy = MMKVUtils.getInstance().commonKV.decodeString("isShowPolicy","");
|
|
|
if (isShowPolicy.isEmpty()){
|
|
|
SdkRequest.getInstance().initAgreement(activity, new IRequestCallback() {
|
|
|
@Override
|
|
@@ -77,17 +81,7 @@ public class CommonOperationManager {
|
|
|
|
|
|
|
|
|
if (resultInfo.code == 400){
|
|
|
- new SingleButtonDialog.Builder(activity)
|
|
|
- .setPositiveButton(new DialogInterface.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
-
|
|
|
- System.exit(0);
|
|
|
- }
|
|
|
- })
|
|
|
- .Create(activity.getString(ResourceUtil.getStringId(activity,"yyxx_comm_network_error_tip")))
|
|
|
- .show();
|
|
|
- return;
|
|
|
+ showExitDialog(activity);
|
|
|
}
|
|
|
String policy_url = "";
|
|
|
|
|
@@ -110,7 +104,8 @@ public class CommonOperationManager {
|
|
|
new PrivacyPolicyDialog(activity, policy_url, new PrivacyPolicyDialog.OnClosePageListener() {
|
|
|
@Override
|
|
|
public void onUserAgreePolicy() {
|
|
|
- SharedPreferencesUtils.setSharedPreferences( Constants.SP_KEY,"isShowPolicy","1",activity);
|
|
|
+
|
|
|
+ MMKVUtils.getInstance().commonKV.encode("isShowPolicy","1");
|
|
|
requestPermission(activity,callback);
|
|
|
}
|
|
|
|
|
@@ -128,23 +123,112 @@ public class CommonOperationManager {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void initialize(Activity activity, Boolean isLandscape, ICallback callback){
|
|
|
+ public void initialize(Activity activity, ICallback callback){
|
|
|
+
|
|
|
+
|
|
|
+ if (!hasIdsRead) {
|
|
|
+ Logger.e("还未读取到ids,将延迟初始化");
|
|
|
+ AtomicInteger timeCount = new AtomicInteger(0);
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ while (!hasIdsRead) {
|
|
|
+ try {
|
|
|
+ Logger.d("还未读取到ids,延迟1s初始化");
|
|
|
+ Thread.sleep(1000);
|
|
|
+ timeCount.getAndIncrement();
|
|
|
+ if (timeCount.get() >= 5) {
|
|
|
+ hasIdsRead = true;
|
|
|
+ }
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ activity.runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (TextUtils.isEmpty(oaid)) {
|
|
|
+ Logger.e("读取到ids失败,共延迟" + timeCount + "s初始化接口,将进行初始化...");
|
|
|
+ } else {
|
|
|
+ Logger.e("读取到ids,共延迟" + timeCount + "s初始化接口,将进行初始化...");
|
|
|
+ }
|
|
|
+
|
|
|
+ startInitSdk(activity, callback);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ } else {
|
|
|
+ Logger.i("读取到ids,开始初始化");
|
|
|
+ startInitSdk(activity, callback);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void startInitSdk(Activity activity, ICallback callback) {
|
|
|
+
|
|
|
SdkRequest.getInstance().initSdk(activity, new IRequestCallback() {
|
|
|
@Override
|
|
|
public void onResponse(ResultInfo resultInfo) {
|
|
|
- Logger.d(resultInfo.msg);
|
|
|
+
|
|
|
+ if (resultInfo.code ==ResultInfo.CODE_SUCCESS){
|
|
|
+ initBean = InitBean.toBean(resultInfo.data);
|
|
|
+ initBean.toString();
|
|
|
+ Logger.i(initBean.toString());
|
|
|
+ callback.onResult(resultInfo.CODE_SUCCESS,activity.getString(ResourceUtil.getStringId(activity,"yyxx_comm_init_success")));
|
|
|
+ }else if (resultInfo.code ==ResultInfo.CODE_FAIL){
|
|
|
+ callback.onResult(resultInfo.CODE_FAIL,activity.getString(ResourceUtil.getStringId(activity,"yyxx_comm_init_fail")));
|
|
|
+ } else if (resultInfo.code ==ResultInfo.CODE_ERROR){
|
|
|
+ showExitDialog(activity);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ void showExitDialog(Activity activity){
|
|
|
+ new SingleButtonDialog.Builder(activity)
|
|
|
+ .setPositiveButton(new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
- public void initMsaDeviceIds(Application application,Context context){
|
|
|
- MsaDeviceIdsHandler.initMsaDeviceIds(application, new IMsaDeviceIdsCallback() {
|
|
|
- @Override
|
|
|
- public void onIdsRead(int code, String msg, Map<String, String> ids) {
|
|
|
+ System.exit(0);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .Create(activity.getString(ResourceUtil.getStringId(activity,"yyxx_comm_network_error_tip")))
|
|
|
+ .show();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void initMsaDeviceIds(Application application){
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ Class<?> billingImpl = Class.forName("cn.yyxx.commsdk.impl.channel.msa.MsaDeviceHandler");
|
|
|
+ Constructor<?> constructor = billingImpl.getDeclaredConstructor();
|
|
|
+ Object impl = constructor.newInstance();
|
|
|
+ Method method = billingImpl.getDeclaredMethod("initMsaDeviceIds", Context.class,IMsaDeviceCallback.class);
|
|
|
+ method.setAccessible(true);
|
|
|
+ method.invoke(impl, application, new IMsaDeviceCallback() {
|
|
|
+ @Override
|
|
|
+ public void onIdsRead(int code, String msg, Map<String, String> ids) {
|
|
|
+ if (code == 0){
|
|
|
+ Logger.i(ids.toString());
|
|
|
+ oaid = ids.get("oaid");
|
|
|
+ }
|
|
|
+ hasIdsRead = true;
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- });
|
|
|
}
|
|
|
@SuppressLint("MissingPermission")
|
|
|
public JSONObject getIfa(Context context){
|
|
@@ -153,7 +237,9 @@ public class CommonOperationManager {
|
|
|
|
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P){
|
|
|
|
|
|
- ifa = MsaDeviceIdsHandler.oaid;
|
|
|
+
|
|
|
+ ifa = oaid;
|
|
|
+
|
|
|
ifa_type = "2";
|
|
|
}else{
|
|
|
if (PermissionKit.isGranted(context,Permission.READ_PHONE_STATE)){
|
|
@@ -190,8 +276,8 @@ public class CommonOperationManager {
|
|
|
|
|
|
static String userSimulateImei(Context context){
|
|
|
|
|
|
- String simulateImei = SharedPreferencesUtils.getSharedPreferences(context,Constants.SP_KEY, "simulateImei");
|
|
|
|
|
|
+ String simulateImei = MMKVUtils.getInstance().commonKV.decodeString("simulateImei","");
|
|
|
if (!simulateImei.isEmpty()){
|
|
|
return simulateImei;
|
|
|
}else {
|
|
@@ -199,8 +285,7 @@ public class CommonOperationManager {
|
|
|
// 用putString的方法保存数据
|
|
|
String encryptMD5to16 ="YYR" + simulateUniqueId().substring(8, 24);
|
|
|
|
|
|
- SharedPreferencesUtils.setSharedPreferences(Constants.SP_KEY,"simulateImei",encryptMD5to16,context);
|
|
|
-
|
|
|
+ MMKVUtils.getInstance().commonKV.encode("simulateImei",encryptMD5to16);
|
|
|
|
|
|
return encryptMD5to16;
|
|
|
}
|
|
@@ -229,6 +314,7 @@ public class CommonOperationManager {
|
|
|
|
|
|
String time = m_szDevIDShort + (System.currentTimeMillis());
|
|
|
return getMD5(time);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public static String getMD5(String content) {
|
|
@@ -258,17 +344,25 @@ public class CommonOperationManager {
|
|
|
|
|
|
void requestPermission(Activity activity,ICallback callback){
|
|
|
|
|
|
+ // 直接跳过,不申请权限
|
|
|
if (!ManifestUtils.getMetaDataValue(activity,"yyxx.SkipPermission").isEmpty()){
|
|
|
- callback.onResult(Constants.CODE_SUCCESS,"User agree policy");
|
|
|
- }else if (!SharedPreferencesUtils.getSharedPreferences(activity,Constants.SP_KEY,"yyxxStopRequestPermission").isEmpty()){
|
|
|
- callback.onResult(Constants.CODE_SUCCESS,"User agree policy");
|
|
|
- }else{
|
|
|
+ callback.onResult(Constants.CODE_SUCCESS,"User skip permission required");
|
|
|
+ }
|
|
|
+ //第二次打开,不再申请权限
|
|
|
+ else if (!MMKVUtils.getInstance().commonKV.decodeString("yyxx.StopRequestPermission","").isEmpty()){
|
|
|
+ callback.onResult(Constants.CODE_SUCCESS,"No more permissions required");
|
|
|
+ }
|
|
|
+ //申请权限
|
|
|
+ else{
|
|
|
goRequestPermission(activity, new PermissonCallBack() {
|
|
|
@Override
|
|
|
public void onResult(Result code) {
|
|
|
if (code == Result.FINISH){
|
|
|
SdkDrive.getInstance().initDrive(activity);
|
|
|
- callback.onResult(Constants.CODE_SUCCESS,"User agree policy");
|
|
|
+ if(!ManifestUtils.getMetaDataValue(activity,"yyxx.StopRequestPermission").isEmpty()){
|
|
|
+ MMKVUtils.getInstance().commonKV.encode("yyxx.StopRequestPermission","1");
|
|
|
+ }
|
|
|
+ callback.onResult(Constants.CODE_SUCCESS,"The permission application is complete");
|
|
|
}
|
|
|
}
|
|
|
});
|