import com.tencent.tinker.loader.app.ApplicationLike; //导入方法依赖的package包/类
/**
* if com.dx168.patchsdk.sample is load, and it crash more than MAX_CRASH_COUNT, then we just clean patch.
*/
private boolean tinkerFastCrashProtect() {
ApplicationLike applicationLike = SampleTinkerManager.getTinkerApplicationLike();
if (applicationLike == null || applicationLike.getApplication() == null) {
return false;
}
if (!TinkerApplicationHelper.isTinkerLoadSuccess(applicationLike)) {
return false;
}
final long elapsedTime = SystemClock.elapsedRealtime() - applicationLike.getApplicationStartElapsedTime();
//this process may not install com.dx168.patchsdk.sample, so we use TinkerApplicationHelper api
if (elapsedTime < QUICK_CRASH_ELAPSE) {
String currentVersion = TinkerApplicationHelper.getCurrentVersion(applicationLike);
if (ShareTinkerInternals.isNullOrNil(currentVersion)) {
return false;
}
SharedPreferences sp = applicationLike.getApplication().getSharedPreferences(ShareConstants.TINKER_SHARE_PREFERENCE_CONFIG, Context.MODE_MULTI_PROCESS);
int fastCrashCount = sp.getInt(currentVersion, 0);
if (fastCrashCount >= MAX_CRASH_COUNT) {
SampleTinkerReport.onFastCrashProtect();
TinkerApplicationHelper.cleanPatch(applicationLike);
TinkerLog.e(TAG, "com.dx168.patchsdk.sample has fast crash more than %d, we just clean patch!", fastCrashCount);
return true;
} else {
sp.edit().putInt(currentVersion, ++fastCrashCount).commit();
TinkerLog.e(TAG, "com.dx168.patchsdk.sample has fast crash %d times", fastCrashCount);
}
}
return false;
}