2020-04-02 10:43:40 +08:00
|
|
|
|
package com.yizhuan.erban.application;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
|
import android.app.ActivityManager;
|
|
|
|
|
import android.app.Application;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.net.http.HttpResponseCache;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.Environment;
|
|
|
|
|
import android.os.StrictMode;
|
2020-04-24 15:14:59 +08:00
|
|
|
|
import androidx.multidex.MultiDex;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.util.ArrayMap;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.security.rp.RPSDK;
|
|
|
|
|
import com.alipay.sdk.app.EnvUtils;
|
|
|
|
|
import com.baidu.mobstat.StatService;
|
|
|
|
|
import com.bumptech.glide.request.target.ViewTarget;
|
|
|
|
|
import com.ishumei.smantifraud.SmAntiFraud;
|
|
|
|
|
import com.llew.huawei.verifier.LoadedApkHuaWei;
|
|
|
|
|
import com.mcxiaoke.packer.helper.PackerNg;
|
|
|
|
|
import com.microquation.linkedme.android.LinkedME;
|
|
|
|
|
import com.mob.MobSDK;
|
|
|
|
|
import com.netease.mobsec.rjsb.watchman;
|
|
|
|
|
import com.netease.nim.uikit.api.NimUIKit;
|
|
|
|
|
import com.netease.nim.uikit.common.util.log.LogUtil;
|
|
|
|
|
import com.netease.nimlib.sdk.NIMClient;
|
|
|
|
|
import com.netease.nimlib.sdk.SDKOptions;
|
|
|
|
|
import com.netease.nimlib.sdk.StatusBarNotificationConfig;
|
|
|
|
|
import com.netease.nimlib.sdk.mixpush.MixPushConfig;
|
2020-04-07 16:41:24 +08:00
|
|
|
|
import com.netease.nimlib.sdk.mixpush.NIMPushClient;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
import com.netease.nimlib.sdk.msg.MessageNotifierCustomization;
|
|
|
|
|
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
|
|
|
|
|
import com.netease.nimlib.sdk.msg.model.IMMessage;
|
|
|
|
|
import com.orhanobut.logger.AndroidLogAdapter;
|
|
|
|
|
import com.orhanobut.logger.Logger;
|
|
|
|
|
import com.scwang.smartrefresh.header.MaterialHeader;
|
|
|
|
|
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
|
|
|
|
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
|
|
|
|
|
import com.squareup.leakcanary.LeakCanary;
|
|
|
|
|
import com.squareup.leakcanary.RefWatcher;
|
|
|
|
|
import com.tencent.bugly.crashreport.CrashReport;
|
|
|
|
|
import com.umeng.analytics.MobclickAgent;
|
|
|
|
|
import com.umeng.commonsdk.UMConfigure;
|
|
|
|
|
import com.yizhuan.erban.BuildConfig;
|
|
|
|
|
import com.yizhuan.erban.MiddleActivity;
|
|
|
|
|
import com.yizhuan.erban.NimMiddleActivity;
|
|
|
|
|
import com.yizhuan.erban.R;
|
|
|
|
|
import com.yizhuan.erban.module_hall.HallDataManager;
|
|
|
|
|
import com.yizhuan.erban.radish.wallet.RadishWalletManager;
|
|
|
|
|
import com.yizhuan.erban.reciever.ConnectiveChangedReceiver;
|
2020-04-07 16:41:24 +08:00
|
|
|
|
import com.yizhuan.erban.utils.PushMessageHandler;
|
2020-04-02 10:43:40 +08:00
|
|
|
|
import com.yizhuan.xchat_android_constants.XChatConstants;
|
|
|
|
|
import com.yizhuan.xchat_android_core.Constants;
|
|
|
|
|
import com.yizhuan.xchat_android_core.DemoCache;
|
|
|
|
|
import com.yizhuan.xchat_android_core.Env;
|
|
|
|
|
import com.yizhuan.xchat_android_core.UriProvider;
|
|
|
|
|
import com.yizhuan.xchat_android_core.auth.AuthModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.channel.ChannelModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.customer_server.CustomerServerModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.domain.model.DomainModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.family.model.FamilyModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.gift.GiftModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment;
|
|
|
|
|
import com.yizhuan.xchat_android_core.im.custom.bean.OpenSignInAttachment;
|
|
|
|
|
import com.yizhuan.xchat_android_core.interceptor.NoParamsInterceptor;
|
|
|
|
|
import com.yizhuan.xchat_android_core.interceptor.ParamsInterceptor;
|
|
|
|
|
import com.yizhuan.xchat_android_core.manager.IMMessageManager;
|
|
|
|
|
import com.yizhuan.xchat_android_core.manager.IMSystemMsgManager;
|
|
|
|
|
import com.yizhuan.xchat_android_core.market_verify.MarketVerifyModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.mentoring_relationship.model.MentoringRelationshipModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.pay.PayModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.public_chat_hall.model.PublicChatHallModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.radish.RadishModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.radish.signin.bean.ImNotice;
|
|
|
|
|
import com.yizhuan.xchat_android_core.room.face.DynamicFaceModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.user.UserModel;
|
|
|
|
|
import com.yizhuan.xchat_android_core.utils.SharedPreferenceUtils;
|
|
|
|
|
import com.yizhuan.xchat_android_library.net.ErBanAllHostnameVerifier;
|
|
|
|
|
import com.yizhuan.xchat_android_library.net.rxnet.RxNet;
|
|
|
|
|
import com.yizhuan.xchat_android_library.utils.AppMetaDataUtil;
|
|
|
|
|
import com.yizhuan.xchat_android_library.utils.AppUtils;
|
|
|
|
|
import com.yizhuan.xchat_android_library.utils.DeviceUuidFactory;
|
|
|
|
|
import com.yizhuan.xchat_android_library.utils.ListUtils;
|
|
|
|
|
import com.yizhuan.xchat_android_library.utils.ProcessUtil;
|
|
|
|
|
import com.yizhuan.xchat_android_library.utils.SystemUtils;
|
|
|
|
|
import com.yizhuan.xchat_android_library.utils.VersionUtil;
|
|
|
|
|
import com.yizhuan.xchat_android_library.utils.config.BasicConfig;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
import io.reactivex.plugins.RxJavaPlugins;
|
|
|
|
|
import io.realm.Realm;
|
|
|
|
|
import io.realm.RealmConfiguration;
|
|
|
|
|
|
|
|
|
|
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author chenran
|
|
|
|
|
* @date 2017/2/11
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public class XChatApplication extends Application {
|
|
|
|
|
public static final String TAG = "XChatApplication";
|
|
|
|
|
private static XChatApplication instance;
|
|
|
|
|
private RefWatcher mRefWatcher;
|
|
|
|
|
|
|
|
|
|
public static XChatApplication instance() {
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//生命周期监听
|
|
|
|
|
private ActivityLifeManager lifeManager;
|
|
|
|
|
|
|
|
|
|
//static 代码段可以防止内存泄露
|
|
|
|
|
static {
|
|
|
|
|
SmartRefreshLayout.setDefaultRefreshHeaderCreater(
|
|
|
|
|
(context, layout) -> {
|
|
|
|
|
// layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);//全局设置主题颜色
|
|
|
|
|
layout.setEnableHeaderTranslationContent(false);
|
|
|
|
|
MaterialHeader materialHeader = new MaterialHeader(context);
|
|
|
|
|
materialHeader.setShowBezierWave(false);
|
|
|
|
|
return materialHeader;
|
|
|
|
|
});
|
|
|
|
|
SmartRefreshLayout.setDefaultRefreshFooterCreater(
|
|
|
|
|
(context, layout) -> new ClassicsFooter(context).setDrawableSize(20));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreate() {
|
|
|
|
|
Log.i("xj-time", System.currentTimeMillis() + "");
|
|
|
|
|
super.onCreate();
|
|
|
|
|
|
|
|
|
|
instance = this;
|
|
|
|
|
String channel = PackerNg.getChannel(this);
|
|
|
|
|
initEnv(channel);
|
2020-04-07 16:41:24 +08:00
|
|
|
|
|
|
|
|
|
// 注册自定义推送消息处理,这个是可选项
|
|
|
|
|
NIMPushClient.registerMixPushMessageHandler(new PushMessageHandler());
|
2020-04-02 10:43:40 +08:00
|
|
|
|
//延迟初始化云信
|
|
|
|
|
NIMClient.init(this, null, options());
|
|
|
|
|
|
|
|
|
|
//logger 配置
|
|
|
|
|
Logger.addLogAdapter(new AndroidLogAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isLoggable(int priority, String tag) {
|
|
|
|
|
return isDebug();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (inMainProcess(this)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RxJavaPlugins.setErrorHandler(throwable -> {
|
|
|
|
|
throwable.printStackTrace();
|
|
|
|
|
// print it
|
|
|
|
|
Log.e(TAG, "the subscribe() method default error handler", throwable);
|
|
|
|
|
});
|
|
|
|
|
//fixed: Glide Exception:"You must not call setTag() on a view Glide is targeting"
|
|
|
|
|
ViewTarget.setTagId(R.id.tag_glide);
|
|
|
|
|
|
|
|
|
|
// 初始化 sp
|
|
|
|
|
SharedPreferenceUtils.init(this);
|
|
|
|
|
|
|
|
|
|
init(channel);
|
|
|
|
|
|
|
|
|
|
initLinkedMe();
|
|
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(channel)) {
|
|
|
|
|
CrashReport.setAppChannel(this, channel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isDebug()) {
|
|
|
|
|
CrashReport.initCrashReport(this.getApplicationContext(), XChatConstants.BUGLY_KEY_RELEASE, false);
|
|
|
|
|
} else {
|
|
|
|
|
CrashReport.initCrashReport(this.getApplicationContext(), XChatConstants.BUGLY_KEY_DEBUG, true);
|
|
|
|
|
}
|
|
|
|
|
//生命周期监听
|
|
|
|
|
if (lifeManager == null) {
|
|
|
|
|
lifeManager = new ActivityLifeManager();
|
|
|
|
|
}
|
|
|
|
|
registerActivityLifecycleCallback(lifeManager);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
dealHuaWeiCrash();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化linkedMe
|
|
|
|
|
*/
|
|
|
|
|
private void initLinkedMe() {
|
|
|
|
|
LinkedME.getInstance(this, XChatConstants.LINKED_ME_KEY);
|
|
|
|
|
if (isDebug()) {
|
|
|
|
|
//设置debug模式下打印LinkedME日志
|
|
|
|
|
LinkedME.getInstance().setDebug();
|
|
|
|
|
}
|
|
|
|
|
//初始时请设置为false
|
|
|
|
|
LinkedME.getInstance().setImmediate(false);
|
|
|
|
|
//设置处理跳转逻辑的中转页,MiddleActivity详见后续配置
|
|
|
|
|
LinkedME.getInstance().setHandleActivity(MiddleActivity.class.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initEnv(String channel) {
|
|
|
|
|
BasicConfig.INSTANCE.setAppContext(this.getApplicationContext());
|
|
|
|
|
|
|
|
|
|
//首先初始化环境
|
|
|
|
|
Env.initEnv(BuildConfig.BUILD_TYPE, BuildConfig.DEBUG);
|
|
|
|
|
|
|
|
|
|
//切换生产坏境和测试环境 true/测试环境 false/生产环境
|
|
|
|
|
BasicConfig.INSTANCE.setDebuggable(Env.isDebug());
|
|
|
|
|
BasicConfig.INSTANCE.setChannel(channel);
|
|
|
|
|
|
|
|
|
|
BasicConfig.INSTANCE.setRootDir(Constants.ERBAN_DIR_NAME);
|
|
|
|
|
BasicConfig.INSTANCE.setLogDir(Constants.LOG_DIR);
|
|
|
|
|
BasicConfig.INSTANCE.setConfigDir(Constants.CONFIG_DIR);
|
|
|
|
|
BasicConfig.INSTANCE.setVoiceDir(Constants.VOICE_DIR);
|
|
|
|
|
BasicConfig.INSTANCE.setCacheDir(Constants.CACHE_DIR);
|
|
|
|
|
BasicConfig.INSTANCE.setImageDir(Constants.IMAGE_CACHE_DIR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void dealHuaWeiCrash() {
|
|
|
|
|
String brand = Build.BRAND;
|
|
|
|
|
String manufacturer = Build.MANUFACTURER;
|
|
|
|
|
if (!TextUtils.isEmpty(brand) && (
|
|
|
|
|
"HUAWEI".toLowerCase().equals(brand.toLowerCase())
|
|
|
|
|
|| "HONOR".toLowerCase().equals(brand.toLowerCase())
|
|
|
|
|
|| "HUAWEI".equals(manufacturer))) {
|
|
|
|
|
LoadedApkHuaWei.hookHuaWeiVerifier(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void attachBaseContext(Context base) {
|
|
|
|
|
super.attachBaseContext(base);
|
|
|
|
|
// you must install multiDex whatever tinker is installed!
|
|
|
|
|
MultiDex.install(base);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onTerminate() {
|
|
|
|
|
super.onTerminate();
|
|
|
|
|
CrashReport.closeBugly();
|
|
|
|
|
if (lifeManager != null) {
|
|
|
|
|
unregisterActivityLifecycleCallbacks(lifeManager);
|
|
|
|
|
}
|
|
|
|
|
GlobalHandleManager.get().unInit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
|
|
|
|
public void registerActivityLifecycleCallback(Application.ActivityLifecycleCallbacks callbacks) {
|
|
|
|
|
this.registerActivityLifecycleCallbacks(callbacks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 云信配置
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public SDKOptions options() {
|
|
|
|
|
SDKOptions options = new SDKOptions();
|
|
|
|
|
options.disableAwake = true;
|
|
|
|
|
options.asyncInitSDK = true;
|
|
|
|
|
if (isDebug()) {
|
|
|
|
|
options.checkManifestConfig = true;
|
|
|
|
|
}
|
|
|
|
|
// 如果将新消息通知提醒托管给 SDK 完成,需要添加以下配置。否则无需设置。
|
|
|
|
|
StatusBarNotificationConfig config = new StatusBarNotificationConfig();
|
|
|
|
|
// 点击通知栏跳转到该Activity
|
|
|
|
|
config.notificationEntrance = NimMiddleActivity.class;
|
|
|
|
|
// config.notificationSmallIconId = R.drawable.icon_msg_normal;
|
|
|
|
|
// 呼吸灯配置
|
|
|
|
|
config.ledARGB = Color.GREEN;
|
|
|
|
|
config.ledOnMs = 1000;
|
|
|
|
|
config.ledOffMs = 1500;
|
|
|
|
|
// 通知铃声的uri字符串
|
|
|
|
|
config.notificationSound = "android.resource://com.netease.nim.demo/raw/msg";
|
|
|
|
|
options.statusBarNotificationConfig = config;
|
|
|
|
|
// 定制通知栏提醒文案(可选,如果不定制将采用SDK默认文案)
|
|
|
|
|
options.messageNotifierCustomization = messageNotifierCustomization;
|
|
|
|
|
|
|
|
|
|
options.appKey = Constants.nimAppKey;
|
|
|
|
|
|
|
|
|
|
// 配置保存图片,文件,log 等数据的目录
|
|
|
|
|
// 如果 options 中没有设置这个值,SDK 会使用下面代码示例中的位置作为 SDK 的数据目录。
|
|
|
|
|
// 该目录目前包含 log, file, image, audio, video, thumb 这6个目录。
|
|
|
|
|
// 如果第三方 APP 需要缓存清理功能, 清理这个目录下面个子目录的内容即可。
|
|
|
|
|
String sdkPath = null;
|
|
|
|
|
try {
|
|
|
|
|
sdkPath = Environment.getExternalStorageDirectory() + "/" + this.getPackageName() + "/nim";
|
|
|
|
|
} catch (ArrayIndexOutOfBoundsException e) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
options.sdkStorageRootPath = sdkPath;
|
|
|
|
|
|
|
|
|
|
// 配置是否需要预下载附件缩略图,默认为 true
|
|
|
|
|
options.preloadAttach = true;
|
|
|
|
|
|
|
|
|
|
// 配置附件缩略图的尺寸大小。表示向服务器请求缩略图文件的大小
|
|
|
|
|
// 该值一般应根据屏幕尺寸来确定, 默认值为 Screen.width / 2
|
|
|
|
|
int widthPixels = this.getResources().getDisplayMetrics().widthPixels;
|
|
|
|
|
options.thumbnailSize = widthPixels / 2;
|
|
|
|
|
// // save cache,留做切换账号备用
|
|
|
|
|
DemoCache.setNotificationConfig(config);
|
|
|
|
|
|
2020-05-05 17:06:10 +08:00
|
|
|
|
/* MixPushConfig mixPushConfig = new MixPushConfig();
|
2020-04-02 10:43:40 +08:00
|
|
|
|
mixPushConfig.hwCertificateName = "tutuHuaweiAndroid";
|
2020-04-07 16:41:24 +08:00
|
|
|
|
|
|
|
|
|
mixPushConfig.mzAppId = "125242";
|
|
|
|
|
mixPushConfig.mzAppKey = "1c478e5eaace4c41ba269d2ca7c9bd69";
|
|
|
|
|
mixPushConfig.mzCertificateName = "qingxunMeizuAndroid2";
|
|
|
|
|
|
|
|
|
|
mixPushConfig.xmAppId = "2882303761518089228";
|
|
|
|
|
mixPushConfig.xmAppKey = "5781808939228";
|
|
|
|
|
mixPushConfig.xmCertificateName = "qingxunXiaomiAndroid";
|
|
|
|
|
|
|
|
|
|
mixPushConfig.vivoCertificateName = "qingxunVivoAndroid";
|
|
|
|
|
|
|
|
|
|
// 下架状态,没有完成接入
|
2020-05-05 17:06:10 +08:00
|
|
|
|
mixPushConfig.oppoAppId = "30156338";
|
|
|
|
|
mixPushConfig.oppoAppKey = "4659eff1cab747c48fb6f44e2f522e83";
|
|
|
|
|
mixPushConfig.oppoAppSercet = "8c6a21854c8045068247c7e1168e29a8";
|
|
|
|
|
mixPushConfig.oppoCertificateName = "qingxunOppoAndroid";
|
2020-04-07 16:41:24 +08:00
|
|
|
|
|
2020-05-05 17:06:10 +08:00
|
|
|
|
options.mixPushConfig = mixPushConfig;*/
|
2020-04-02 10:43:40 +08:00
|
|
|
|
|
|
|
|
|
return options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MessageNotifierCustomization messageNotifierCustomization = new MessageNotifierCustomization() {
|
|
|
|
|
@Override
|
|
|
|
|
public String makeNotifyContent(String nick, IMMessage message) {
|
|
|
|
|
if (message.getMsgType() == MsgTypeEnum.custom) {
|
|
|
|
|
CustomAttachment customAttachment = (CustomAttachment) message.getAttachment();
|
|
|
|
|
if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI) {
|
|
|
|
|
return message.getFromNick();
|
|
|
|
|
} else if (customAttachment instanceof OpenSignInAttachment) {
|
|
|
|
|
return getContentFromOpenSignIn(customAttachment);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 采用SDK默认文案
|
|
|
|
|
return "收到一条消息";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String makeTicker(String nick, IMMessage message) {
|
|
|
|
|
if (message.getMsgType() == MsgTypeEnum.custom) {
|
|
|
|
|
CustomAttachment customAttachment = (CustomAttachment) message.getAttachment();
|
|
|
|
|
if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI) {
|
|
|
|
|
return message.getFromNick();
|
|
|
|
|
} else if (customAttachment instanceof OpenSignInAttachment) {
|
|
|
|
|
return getContentFromOpenSignIn(customAttachment);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 采用SDK默认文案
|
|
|
|
|
return "收到一条消息";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getContentFromOpenSignIn(CustomAttachment attachment) {
|
|
|
|
|
String result = null;
|
|
|
|
|
if (attachment instanceof OpenSignInAttachment) {
|
|
|
|
|
ImNotice notice = ((OpenSignInAttachment) attachment).getImNotice();
|
|
|
|
|
if (notice != null) {
|
|
|
|
|
result = notice.getContent();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (TextUtils.isEmpty(result)) {
|
|
|
|
|
result = "收到一条消息";
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String makeRevokeMsgTip(String s, IMMessage imMessage) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断当前进程是否主进程
|
|
|
|
|
*
|
|
|
|
|
* @param context
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private static boolean inMainProcess(Context context) {
|
|
|
|
|
String packageName = context.getPackageName();
|
|
|
|
|
String processName = getProcessName(context);
|
|
|
|
|
return packageName.equals(processName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前进程名
|
|
|
|
|
*
|
|
|
|
|
* @param context
|
|
|
|
|
* @return 进程名
|
|
|
|
|
*/
|
|
|
|
|
public static String getProcessName(Context context) {
|
|
|
|
|
String processName = null;
|
|
|
|
|
|
|
|
|
|
// ActivityManager
|
|
|
|
|
ActivityManager am = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE));
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
for (ActivityManager.RunningAppProcessInfo info : am.getRunningAppProcesses()) {
|
|
|
|
|
if (info.pid == android.os.Process.myPid()) {
|
|
|
|
|
processName = info.processName;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// go home
|
|
|
|
|
if (!TextUtils.isEmpty(processName)) {
|
|
|
|
|
return processName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// take a rest and again
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(100L);
|
|
|
|
|
} catch (InterruptedException ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化RxNet
|
|
|
|
|
*
|
|
|
|
|
* @param context
|
|
|
|
|
* @param url
|
|
|
|
|
*/
|
|
|
|
|
@SuppressLint("CheckResult")
|
|
|
|
|
public void initRxNet(Context context, String url) {
|
|
|
|
|
Map<String, String> httpParams = new ArrayMap<>();
|
|
|
|
|
httpParams.put("os", "android");
|
|
|
|
|
httpParams.put("osVersion", Build.VERSION.RELEASE);
|
|
|
|
|
httpParams.put("app", "qingxun");
|
|
|
|
|
httpParams.put("ispType", String.valueOf(SystemUtils.getIspType(context)));
|
|
|
|
|
httpParams.put("netType", String.valueOf(SystemUtils.getNetworkType(context)));
|
|
|
|
|
httpParams.put("model", SystemUtils.getPhoneModel());
|
|
|
|
|
httpParams.put("appVersion", VersionUtil.getLocalName(context));
|
|
|
|
|
httpParams.put("appVersionCode", String.valueOf(AppUtils.getVersionCode(context)));
|
|
|
|
|
httpParams.put("deviceId", DeviceUuidFactory.getDeviceId(context));
|
|
|
|
|
httpParams.put("channel", AppMetaDataUtil.getChannelID());
|
|
|
|
|
RxNet.init(context)
|
|
|
|
|
.debug(isDebug())
|
|
|
|
|
.setBaseUrl(url)
|
|
|
|
|
.addInterceptors(new ParamsInterceptor(httpParams))
|
|
|
|
|
.addInterceptors(new NoParamsInterceptor())//注意:拦截器的添加顺序,请求的拦截顺序
|
|
|
|
|
//.addInterceptors(new DomainInterceptor())
|
|
|
|
|
.certificates()
|
|
|
|
|
.hostnameVerifier(new ErBanAllHostnameVerifier())
|
|
|
|
|
.build();
|
|
|
|
|
//单例的model 初始化
|
|
|
|
|
initModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initDomain(Context context, String url) {
|
|
|
|
|
// 从缓存中读出上一次可用的域名
|
|
|
|
|
String availableHost = (String) SharedPreferenceUtils.get(DomainModel.KEY_AVAILABLE_HOST, "");
|
|
|
|
|
LogUtil.e(TAG, "initDomain: 从缓存中读出上一次可用的域名: " + availableHost);
|
|
|
|
|
LogUtil.e(TAG, "initDomain: 编译时生成的域名: " + url);
|
|
|
|
|
// 如果缓存域名为空,则使用 BuildConfig 里面的域名
|
|
|
|
|
String h5Url = TextUtils.isEmpty(availableHost) ? url : DomainModel.getInstance().getBaseUrl(availableHost);
|
|
|
|
|
// 强行用从缓存里读出来的域名给 H5 调用
|
|
|
|
|
UriProvider.initUri(h5Url, h5Url, h5Url);
|
|
|
|
|
// 先初始化 RxNet,否则后面的 initModel 会有各种问题
|
|
|
|
|
initRxNet(context, url);
|
|
|
|
|
// 从内存里获得硬编码的域名列表
|
|
|
|
|
List<String> domainList = DomainModel.getInstance().getDomainList();
|
|
|
|
|
LogUtil.e(TAG, "initDomain: 从内存里获得预配置的域名文件");
|
|
|
|
|
if (!ListUtils.isListEmpty(domainList)) {
|
|
|
|
|
for (String domain : domainList) {
|
|
|
|
|
LogUtil.e(TAG, "initDomain: 域名: " + domain);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
LogUtil.e(TAG, "initDomain: 预设置域名为空");
|
|
|
|
|
}
|
|
|
|
|
// 从缓存中读出之前从 client/init 里得到的候选域名名单
|
|
|
|
|
List<String> lastInitDomainList = DemoCache.readInitDataApiHost();
|
|
|
|
|
LogUtil.e(TAG, "initDomain: 从缓存中读出之前从 client/init 里得到的候选域名名单");
|
|
|
|
|
if (!ListUtils.isListEmpty(lastInitDomainList)) {
|
|
|
|
|
for (String domain : lastInitDomainList) {
|
|
|
|
|
LogUtil.e(TAG, "initDomain: 域名: " + domain);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
LogUtil.e(TAG, "initDomain: 从缓存中读出之前从 client/init 里得到的候选域名名单为空");
|
|
|
|
|
}
|
|
|
|
|
// 默认把初始域名插到检测列表的头部
|
|
|
|
|
domainList.add(0, url);
|
|
|
|
|
// 候选域名列表插到检测列表的尾部
|
|
|
|
|
if (!ListUtils.isListEmpty(lastInitDomainList)) {
|
|
|
|
|
domainList.addAll(lastInitDomainList);
|
|
|
|
|
}
|
|
|
|
|
LogUtil.e(TAG, "initDomain: 组合域名列表");
|
|
|
|
|
for (String domain : domainList) {
|
|
|
|
|
// 检测可用的域名
|
|
|
|
|
DomainModel.getInstance()
|
|
|
|
|
.analyseDomain(domain)
|
|
|
|
|
.subscribe();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void init(String channel) {
|
|
|
|
|
initNimUIKit();
|
|
|
|
|
initYiDun();
|
2020-04-03 16:54:53 +08:00
|
|
|
|
// initShuMeiTianWang(channel); //暂时不用
|
2020-04-02 10:43:40 +08:00
|
|
|
|
MobSDK.init(this);
|
|
|
|
|
UriProvider.initUri(BuildConfig.BASE_URL_DEBUG, BuildConfig.BASE_URL_STAGING, BuildConfig.BASE_URL_RELEASE);
|
|
|
|
|
try {
|
|
|
|
|
/** svga动画缓存路径 */
|
|
|
|
|
File cacheDir = new File(this.getApplicationContext().getExternalCacheDir(), "http");
|
|
|
|
|
if (!cacheDir.exists()) cacheDir.mkdirs();
|
|
|
|
|
HttpResponseCache.install(cacheDir, 1024 * 1024 * 128);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
Log.e(TAG, "testtest", e);
|
|
|
|
|
}
|
|
|
|
|
// url
|
|
|
|
|
// if (Env.getCurrentEnv() == Env.EnvType.Staging) {
|
|
|
|
|
// // 预发布环境下不走动态域名的逻辑
|
|
|
|
|
// initRxNet(BasicConfig.INSTANCE.getAppContext(), BuildConfig.BASE_URL_STAGING);
|
|
|
|
|
// } else {
|
|
|
|
|
// initDomain(BasicConfig.INSTANCE.getAppContext(), UriProvider.JAVA_WEB_URL);
|
|
|
|
|
// }
|
|
|
|
|
initRxNet(BasicConfig.INSTANCE.getAppContext(), UriProvider.JAVA_WEB_URL);
|
|
|
|
|
|
|
|
|
|
//内存泄漏监控
|
|
|
|
|
setupLeakCanary();
|
|
|
|
|
ConnectiveChangedReceiver.getInstance().init(this.getApplicationContext());
|
|
|
|
|
/**
|
|
|
|
|
* 使用到realm 数据库,这里配置数据库 这里必须先于模块初始化前进行初始化配置
|
|
|
|
|
*/
|
|
|
|
|
Realm.init(BasicConfig.INSTANCE.getAppContext());
|
|
|
|
|
RealmConfiguration config = new RealmConfiguration.Builder()
|
2020-04-03 16:54:53 +08:00
|
|
|
|
.name("accompany.realm")
|
2020-04-02 10:43:40 +08:00
|
|
|
|
.deleteRealmIfMigrationNeeded()
|
|
|
|
|
.build();
|
|
|
|
|
Realm.setDefaultConfiguration(config);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LogUtil.i(TAG, channel);
|
2020-04-03 16:54:53 +08:00
|
|
|
|
// initBaiduStatistic(channel); 百度统计
|
2020-04-02 10:43:40 +08:00
|
|
|
|
initUmengAppStatistic(channel);
|
|
|
|
|
|
|
|
|
|
if (isDebug()) {
|
|
|
|
|
//禁掉沙盒模式
|
2020-04-07 16:41:24 +08:00
|
|
|
|
EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX);
|
2020-04-02 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RPSDK.initialize(getApplicationContext());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 一些单例的 model
|
|
|
|
|
*/
|
|
|
|
|
private void initModel() {
|
|
|
|
|
DynamicFaceModel.get().init();
|
|
|
|
|
// RedPacketModel.get();
|
|
|
|
|
PayModel.get();
|
|
|
|
|
UserModel.get();
|
|
|
|
|
//ui层的萝卜钱包
|
|
|
|
|
RadishWalletManager.get();
|
|
|
|
|
//model层的
|
|
|
|
|
RadishModel.get();
|
|
|
|
|
|
|
|
|
|
IMMessageManager.get().init();
|
|
|
|
|
IMSystemMsgManager.get().init();
|
|
|
|
|
|
|
|
|
|
FamilyModel.Instance();
|
|
|
|
|
AuthModel.get();
|
|
|
|
|
|
|
|
|
|
ChannelModel.get();
|
|
|
|
|
MarketVerifyModel.get();
|
|
|
|
|
GiftModel.get();
|
|
|
|
|
PublicChatHallModel.get();
|
|
|
|
|
// 模厅
|
|
|
|
|
HallDataManager.get().application();
|
|
|
|
|
// HallModel.get();
|
|
|
|
|
// 师徒
|
|
|
|
|
MentoringRelationshipModel.get();
|
|
|
|
|
|
|
|
|
|
//初始化客服系统
|
|
|
|
|
CustomerServerModel.getInstance().init(this);
|
|
|
|
|
//全局处理
|
|
|
|
|
GlobalHandleManager.get().init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initBaiduStatistic(String channel) {
|
|
|
|
|
// 百度统计初始化
|
|
|
|
|
StatService.setAppKey(Constants.BAIDU_APPKEY);
|
|
|
|
|
StatService.setAppChannel(this.getApplicationContext(), channel, true);
|
|
|
|
|
StatService.setOn(this.getApplicationContext(), StatService.EXCEPTION_LOG);
|
|
|
|
|
StatService.setSessionTimeOut(30);
|
|
|
|
|
StatService.setDebugOn(isDebug());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initUmengAppStatistic(String channel) {
|
|
|
|
|
// 友盟统计初始化
|
|
|
|
|
UMConfigure.init(this.getApplicationContext(), XChatConstants.UMENG_APP_KEY,
|
|
|
|
|
channel, UMConfigure.DEVICE_TYPE_PHONE, null);
|
|
|
|
|
// 选用MANUAL页面采集模式
|
|
|
|
|
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.MANUAL);
|
|
|
|
|
// 支持在子进程中统计自定义事件
|
|
|
|
|
UMConfigure.setProcessEvent(true);
|
|
|
|
|
// 日志加密
|
|
|
|
|
UMConfigure.setEncryptEnabled(true);
|
|
|
|
|
// 集成测试
|
|
|
|
|
UMConfigure.setLogEnabled(isRealDebug());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initNimUIKit() {
|
|
|
|
|
// 初始化
|
|
|
|
|
NimUIKit.init(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initYiDun() {
|
|
|
|
|
// 网易易盾初始化
|
|
|
|
|
watchman.init(this, XChatConstants.YI_DUN_PRODUCT_NUMBER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initShuMeiTianWang(String channel) {
|
|
|
|
|
// 数美天网初始化
|
|
|
|
|
if (Objects.equals(ProcessUtil.getCurProcessName(this), this.getPackageName())) {
|
|
|
|
|
SmAntiFraud.SmOption option = new SmAntiFraud.SmOption();
|
|
|
|
|
String DEBUG_ORG = XChatConstants.SHU_MEI_TIAN_WANG_ORGANIZATION;// organization 代码 不要传 AccessKey
|
|
|
|
|
option.setOrganization(DEBUG_ORG);
|
|
|
|
|
option.setChannel(channel);//渠道代码
|
|
|
|
|
SmAntiFraud.create(this, option);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setupLeakCanary() {
|
|
|
|
|
if (!BasicConfig.INSTANCE.isDebuggable()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (LeakCanary.isInAnalyzerProcess(this)) {
|
|
|
|
|
// This process is dedicated to LeakCanary for heap analysis.
|
|
|
|
|
// You should not init your app in this process.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// enabledStrictMode();
|
|
|
|
|
mRefWatcher = LeakCanary.install(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void enabledStrictMode() {
|
|
|
|
|
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
|
|
|
|
|
.detectAll() //检测所有的想检测的
|
|
|
|
|
// .detectCustomSlowCalls() //自定义的耗时调用
|
|
|
|
|
// .detectDiskReads() /*检测磁盘读操作*/
|
|
|
|
|
// .detectDiskWrites() /*检测磁盘写入操作*/
|
|
|
|
|
// .detectNetwork() //检测网络
|
|
|
|
|
// .detectResourceMismatches()
|
|
|
|
|
.penaltyLog()
|
|
|
|
|
.penaltyDeath()
|
|
|
|
|
.build());
|
|
|
|
|
|
|
|
|
|
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
|
|
|
|
|
.detectAll()/*也可以采用detectAll()来检测所有想检测的东西*/
|
|
|
|
|
// .detectActivityLeaks()/*检测Activity内存泄露*/
|
|
|
|
|
// .detectLeakedClosableObjects()/*检测未关闭的Closable对象*/
|
|
|
|
|
// .detectLeakedSqlLiteObjects() /*检测Sqlite对象是否关闭*/
|
|
|
|
|
.penaltyLog()
|
|
|
|
|
.penaltyDeath()
|
|
|
|
|
.build()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static RefWatcher getRefWatcher(Context context) {
|
|
|
|
|
return instance().mRefWatcher;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* debug 环境 受到实验室模式影响
|
|
|
|
|
*/
|
|
|
|
|
public static boolean isDebug() {
|
|
|
|
|
return Env.isDebug();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 是否是真实的debug的环境 不受实验室模式影响
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static boolean isRealDebug() {
|
|
|
|
|
return Env.isRealDebug();
|
|
|
|
|
}
|
|
|
|
|
}
|