本文整理汇总了Java中com.tencent.tinker.loader.shareutil.SharePatchFileUtil类的典型用法代码示例。如果您正苦于以下问题:Java SharePatchFileUtil类的具体用法?Java SharePatchFileUtil怎么用?Java SharePatchFileUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SharePatchFileUtil类属于com.tencent.tinker.loader.shareutil包,在下文中一共展示了SharePatchFileUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onLoadException
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
@Override
public void onLoadException(Throwable e, int errorCode) {
super.onLoadException(e, errorCode);
switch (errorCode) {
case ShareConstants.ERROR_LOAD_EXCEPTION_UNCAUGHT:
String uncaughtString = SharePatchFileUtil.checkTinkerLastUncaughtCrash(context);
if (!ShareTinkerInternals.isNullOrNil(uncaughtString)) {
File laseCrashFile = SharePatchFileUtil.getPatchLastCrashFile(context);
SharePatchFileUtil.safeDeleteFile(laseCrashFile);
// found really crash reason
TinkerLog.e(TAG, "tinker uncaught real exception:" + uncaughtString);
}
break;
}
SampleTinkerReport.onLoadException(e, errorCode);
}
示例2: onPatchListenerCheck
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
public boolean onPatchListenerCheck(String md5) {
if (!isRetryEnable) {
TinkerLog.w(TAG, "onPatchListenerCheck retry disabled, just return");
return true;
}
if (!retryInfoFile.exists()) {
TinkerLog.w(TAG, "onPatchListenerCheck retry file is not exist, just return");
return true;
}
if (md5 == null) {
TinkerLog.w(TAG, "onPatchListenerCheck md5 is null, just return");
return true;
}
RetryInfo retryInfo = RetryInfo.readRetryProperty(retryInfoFile);
if (md5.equals(retryInfo.md5)) {
int nowTimes = Integer.parseInt(retryInfo.times);
if (nowTimes >= RETRY_MAX_COUNT) {
TinkerLog.w(TAG, "onPatchListenerCheck, retry count %d must exceed than max retry count", nowTimes);
SharePatchFileUtil.safeDeleteFile(tempPatchFile);
return false;
}
}
return true;
}
示例3: Builder
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
/**
* Start building a new {@link Tinker} instance.
*/
public Builder(Context context) {
if (context == null) {
throw new TinkerRuntimeException("Context must not be null.");
}
this.context = context;
this.mainProcess = TinkerServiceInternals.isInMainProcess(context);
this.patchProcess = TinkerServiceInternals.isInTinkerPatchServiceProcess(context);
this.patchDirectory = SharePatchFileUtil.getPatchDirectory(context);
if (this.patchDirectory == null) {
TinkerLog.e(TAG, "patchDirectory is null!");
return;
}
this.patchInfoFile = SharePatchFileUtil.getPatchInfoFile(patchDirectory.getAbsolutePath());
this.patchInfoLockFile = SharePatchFileUtil.getPatchInfoLockFile(patchDirectory.getAbsolutePath());
TinkerLog.w(TAG, "tinker patch directory: %s", patchDirectory);
}
示例4: retryPatch
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
public boolean retryPatch() {
final Tinker tinker = Tinker.with(context);
if (!tinker.isMainProcess()) {
return false;
}
File patchVersionFile = tinker.getTinkerLoadResultIfPresent().patchVersionFile;
if (patchVersionFile != null) {
if (UpgradePatchRetry.getInstance(context).onPatchListenerCheck(SharePatchFileUtil.getMD5(patchVersionFile))) {
TinkerLog.i(TAG, "try to repair oat file on patch process");
TinkerInstaller.onReceiveUpgradePatch(context, patchVersionFile.getAbsolutePath());
return true;
}
// else {
// TinkerLog.i(TAG, "repair retry exceed must max time, just clean");
// checkAndCleanPatch();
// }
}
return false;
}
示例5: deleteRawPatchFile
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
/**
* don't delete tinker version file
* @param rawFile
*/
public void deleteRawPatchFile(File rawFile) {
if (!SharePatchFileUtil.isLegalFile(rawFile)) {
return;
}
TinkerLog.w(TAG, "deleteRawPatchFile rawFile path: %s", rawFile.getPath());
String fileName = rawFile.getName();
if (!fileName.startsWith(ShareConstants.PATCH_BASE_NAME)
|| !fileName.endsWith(ShareConstants.PATCH_SUFFIX)) {
SharePatchFileUtil.safeDeleteFile(rawFile);
return;
}
File parentFile = rawFile.getParentFile();
if (!parentFile.getName().startsWith(ShareConstants.PATCH_BASE_NAME)) {
SharePatchFileUtil.safeDeleteFile(rawFile);
} else {
File grandFile = parentFile.getParentFile();
if (!grandFile.getName().equals(ShareConstants.PATCH_DIRECTORY_NAME)) {
SharePatchFileUtil.safeDeleteFile(rawFile);
}
}
}
示例6: onPatchListenerCheck
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
public boolean onPatchListenerCheck(String md5) {
if (!isRetryEnable) {
TinkerLog.w(TAG, "onPatchListenerCheck retry disabled, just return");
return true;
}
if (!retryInfoFile.exists()) {
TinkerLog.w(TAG, "onPatchListenerCheck retry file is not exist, just return");
return true;
}
if (md5 == null) {
TinkerLog.w(TAG, "onPatchListenerCheck md5 is null, just return");
return true;
}
RetryInfo retryInfo = RetryInfo.readRetryProperty(retryInfoFile);
if (md5.equals(retryInfo.md5)) {
int nowTimes = Integer.parseInt(retryInfo.times);
if (nowTimes >= maxRetryCount) {
TinkerLog.w(TAG, "onPatchListenerCheck, retry count %d must exceed than max retry count", nowTimes);
SharePatchFileUtil.safeDeleteFile(tempPatchFile);
return false;
}
}
return true;
}
示例7: Builder
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
public Builder(Context context) {
if (context == null) {
throw new TinkerRuntimeException("Context must not be null.");
}
this.context = context;
this.mainProcess = ShareTinkerInternals.isInMainProcess(context);
this.patchProcess = TinkerServiceInternals.isInTinkerPatchServiceProcess(context);
this.patchDirectory = SharePatchFileUtil.getPatchDirectory(context);
if (this.patchDirectory == null) {
TinkerLog.e(Tinker.TAG, "patchDirectory is null!", new Object[0]);
return;
}
this.patchInfoFile = SharePatchFileUtil.getPatchInfoFile(this.patchDirectory
.getAbsolutePath());
TinkerLog.w(Tinker.TAG, "tinker patch directory: %s", this.patchDirectory);
}
示例8: onLoadPatchVersionChanged
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
public void onLoadPatchVersionChanged(String oldVersion, String newVersion, File
patchDirectoryFile, String currentPatchName) {
int i = 0;
TinkerLog.i(TAG, "patch version change from " + oldVersion + " to " + newVersion, new
Object[0]);
if (oldVersion != null && newVersion != null && !oldVersion.equals(newVersion) && Tinker
.with(this.context).isMainProcess()) {
TinkerLog.i(TAG, "try kill all other process", new Object[0]);
ShareTinkerInternals.killAllOtherProcess(this.context);
File[] files = patchDirectoryFile.listFiles();
if (files != null) {
int length = files.length;
while (i < length) {
File file = files[i];
String name = file.getName();
if (file.isDirectory() && !name.equals(currentPatchName)) {
SharePatchFileUtil.deleteDir(file);
}
i++;
}
}
}
}
示例9: onPatchResult
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
public void onPatchResult(PatchResult result) {
if (result == null) {
TinkerLog.e(TAG, "DefaultTinkerResultService received null result!!!!", new Object[0]);
return;
}
TinkerLog.i(TAG, "DefaultTinkerResultService received a result:%s ", result.toString());
TinkerServiceInternals.killTinkerPatchServiceProcess(getApplicationContext());
if (result.isSuccess && result.isUpgradePatch) {
File rawFile = new File(result.rawPatchFilePath);
if (rawFile.exists()) {
TinkerLog.i(TAG, "save delete raw patch file", new Object[0]);
SharePatchFileUtil.safeDeleteFile(rawFile);
}
if (checkIfNeedKill(result)) {
Process.killProcess(Process.myPid());
} else {
TinkerLog.i(TAG, "I have already install the newly patch version!", new Object[0]);
}
}
if (!result.isSuccess && !result.isUpgradePatch) {
Tinker.with(getApplicationContext()).cleanPatch();
}
}
示例10: extractDexToJar
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
private static void extractDexToJar(File dex) throws IOException {
FileOutputStream fos = new FileOutputStream(dex + ".jar");
InputStream in = new FileInputStream(dex);
ZipOutputStream zos = null;
BufferedInputStream bis = null;
try {
zos = new ZipOutputStream(new
BufferedOutputStream(fos));
bis = new BufferedInputStream(in);
byte[] buffer = new byte[ShareConstants.BUFFER_SIZE];
ZipEntry entry = new ZipEntry(ShareConstants.DEX_IN_JAR);
zos.putNextEntry(entry);
int length = bis.read(buffer);
while (length != -1) {
zos.write(buffer, 0, length);
length = bis.read(buffer);
}
zos.closeEntry();
} finally {
SharePatchFileUtil.closeQuietly(bis);
SharePatchFileUtil.closeQuietly(zos);
}
}
示例11: handlePatchFile
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
private boolean handlePatchFile(Context context, Integer version, File patchFile) {
SharedPreferences sp = context.getSharedPreferences(
TinkerServerClient.SHARE_SERVER_PREFERENCE_CONFIG, Context.MODE_PRIVATE
);
int current = sp.getInt(TINKER_RETRY_PATCH, 0);
if (current >= TINKER_MAX_RETRY_COUNT) {
SharePatchFileUtil.safeDeleteFile(patchFile);
sp.edit().putInt(TINKER_RETRY_PATCH, 0).commit();
TinkerLog.w(TAG,
"beforePatchRequest, retry patch install more than %d times, version: %d, patch:%s",
current, version, patchFile.getPath()
);
} else {
TinkerLog.w(TAG, "beforePatchRequest, have pending patch to install, version: %d, patch:%s",
version, patchFile.getPath()
);
sp.edit().putInt(TINKER_RETRY_PATCH, ++current).commit();
TinkerInstaller.onReceiveUpgradePatch(context, patchFile.getAbsolutePath());
return true;
}
return false;
}
示例12: readVersionProperty
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
private void readVersionProperty() {
if (versionFile == null || !versionFile.exists() || versionFile.length() == 0) {
return;
}
Properties properties = new Properties();
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(versionFile);
properties.load(inputStream);
uuid = properties.getProperty(UUID_VALUE);
appVersion = properties.getProperty(APP_VERSION);
grayValue = ServerUtils.stringToInteger(properties.getProperty(GRAY_VALUE));
patchVersion = ServerUtils.stringToInteger(properties.getProperty(CURRENT_VERSION));
patchMd5 = properties.getProperty(CURRENT_MD5);
} catch (IOException e) {
TinkerLog.e(TAG, "readVersionProperty exception:" + e);
} finally {
SharePatchFileUtil.closeQuietly(inputStream);
}
}
示例13: onPatchUpgrade
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
@Override
public boolean onPatchUpgrade(File file, Integer newVersion, Integer currentVersion) {
TinkerLog.i(TAG, "onPatchUpgrade, file:%s, newVersion:%d, currentVersion:%d",
file.getPath(), newVersion, currentVersion);
TinkerServerClient client = TinkerServerClient.get();
Context context = client.getContext();
client.reportPatchDownloadSuccess(newVersion);
ShareSecurityCheck securityCheck = new ShareSecurityCheck(context);
if (!securityCheck.verifyPatchMetaSignature(file)) {
TinkerLog.e(TAG, "onPatchUpgrade, signature check fail. file: %s, version:%d", file.getPath(), newVersion);
//treat it as download fail
if (increaseDownloadError(context)) {
//update tinker version also, don't request again
client.updateTinkerVersion(newVersion, SharePatchFileUtil.getMD5(file));
client.reportPatchFail(newVersion, ERROR_DOWNLOAD_CHECK_FAIL);
}
SharePatchFileUtil.safeDeleteFile(file);
return false;
}
tryPatchFile(file, newVersion);
return true;
}
示例14: tryPatchFile
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
private void tryPatchFile(File patchFile, Integer newVersion) {
TinkerServerClient client = TinkerServerClient.get();
Context context = client.getContext();
//In order to calculate the user number, just report success here
String patchMd5 = SharePatchFileUtil.getMD5(patchFile);
//update version
client.updateTinkerVersion(newVersion, patchMd5);
//delete old patch sever file
File serverDir = ServerUtils.getServerDirectory(context);
if (serverDir != null) {
File[] files = serverDir.listFiles();
if (files != null) {
String currentName = patchFile.getName();
for (File file : files) {
String fileName = file.getName();
if (fileName.equals(currentName) || fileName.equals(ServerUtils.TINKER_VERSION_FILE)) {
continue;
}
SharePatchFileUtil.safeDeleteFile(file);
}
}
client.reportPatchApplySuccess(newVersion);
//try install
TinkerInstaller.onReceiveUpgradePatch(context, patchFile.getAbsolutePath());
}
}
示例15: onLoadFileNotFound
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入依赖的package包/类
/**
* try to recover patch oat file
* @param file
* @param fileType
* @param isDirectory
*/
@Override
public void onLoadFileNotFound(File file, int fileType, boolean isDirectory) {
TinkerLog.i(TAG, "patch loadReporter onLoadFileNotFound: patch file not found: %s, fileType:%d, isDirectory:%b",
file.getAbsolutePath(), fileType, isDirectory);
// only try to recover opt file
// check dex opt file at last, some phone such as VIVO/OPPO like to change dex2oat to interpreted
if (fileType == ShareConstants.TYPE_DEX_OPT) {
Tinker tinker = Tinker.with(context);
//we can recover at any process except recover process
if (tinker.isMainProcess()) {
File patchVersionFile = tinker.getTinkerLoadResultIfPresent().patchVersionFile;
if (patchVersionFile != null) {
if (UpgradePatchRetry.getInstance(context).onPatchListenerCheck(SharePatchFileUtil.getMD5(patchVersionFile))) {
TinkerLog.i(TAG, "try to repair oat file on patch process");
TinkerInstaller.onReceiveUpgradePatch(context, patchVersionFile.getAbsolutePath());
} else {
TinkerLog.i(TAG, "repair retry exceed must max time, just clean");
checkAndCleanPatch();
}
}
}
} else {
checkAndCleanPatch();
}
SampleTinkerReport.onLoadFileNotFound(fileType);
}