com.tencent.tinker.loader.shareutil.ShareConstants Java Examples

The following examples show how to use com.tencent.tinker.loader.shareutil.ShareConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TinkerServerManager.java    From tinkerpatch-sdk with MIT License 6 votes vote down vote up
/**
 * 上报补丁合成情况
 * @param patchMd5
 */
public static void reportTinkerPatchListenerFail(int returnCode, String patchMd5) {
    if (sTinkerServerClient == null) {
        TinkerLog.e(TAG, "reportTinkerPatchListenerFail, sTinkerServerClient == null");
        return;
    }
    if (returnCode == ShareConstants.ERROR_PATCH_OK) {
        return;
    }
    if (patchMd5 == null) {
        TinkerLog.e(TAG, "reportTinkerPatchListenerFail, patchMd5 == null");
        return;
    }
    if (!patchMd5.equals(sTinkerServerClient.getCurrentPatchMd5())) {
        TinkerLog.e(TAG, "reportTinkerPatchListenerFail, md5 not equal, patchMd5:%s, currentPatchMd5:%s",
            patchMd5, sTinkerServerClient.getCurrentPatchMd5()
        );
        return;
    }
    sTinkerServerClient.reportPatchFail(
        sTinkerServerClient.getCurrentPatchVersion(),
        DefaultPatchRequestCallback.ERROR_LISTENER_CHECK_FAIL
    );
}
 
Example #2
Source File: SampleTinkerReport.java    From tinker-manager with Apache License 2.0 6 votes vote down vote up
public static void onLoadFileNotFound(int fileType) {
    if (reporter == null) {
        return;
    }
    switch (fileType) {
        case ShareConstants.TYPE_DEX_OPT:
            reporter.onReport(KEY_LOADED_MISSING_DEX_OPT);
            break;
        case ShareConstants.TYPE_DEX:
            reporter.onReport(KEY_LOADED_MISSING_DEX);
            break;
        case ShareConstants.TYPE_LIBRARY:
            reporter.onReport(KEY_LOADED_MISSING_LIB);
            break;
        case ShareConstants.TYPE_PATCH_FILE:
            reporter.onReport(KEY_LOADED_MISSING_PATCH_FILE);
            break;
        case ShareConstants.TYPE_PATCH_INFO:
            reporter.onReport(KEY_LOADED_MISSING_PATCH_INFO);
            break;
        case ShareConstants.TYPE_RESOURCE:
            reporter.onReport(KEY_LOADED_MISSING_RES);
            break;
    }
}
 
Example #3
Source File: SampleTinkerReport.java    From tinker-manager with Apache License 2.0 6 votes vote down vote up
public static void onLoadInterpretReport(int type, Throwable e) {
    if (reporter == null) {
        return;
    }
    switch (type) {
        case ShareConstants.TYPE_INTERPRET_GET_INSTRUCTION_SET_ERROR:
            reporter.onReport(KEY_LOADED_INTERPRET_GET_INSTRUCTION_SET_ERROR);
            reporter.onReport("Tinker Exception:interpret occur exception " + SampleUtils.getExceptionCauseString(e));
            break;
        case ShareConstants.TYPE_INTERPRET_COMMAND_ERROR:
            reporter.onReport(KEY_LOADED_INTERPRET_INTERPRET_COMMAND_ERROR);
            reporter.onReport("Tinker Exception:interpret occur exception " + SampleUtils.getExceptionCauseString(e));
            break;
        case ShareConstants.TYPE_INTERPRET_OK:
            reporter.onReport(KEY_LOADED_INTERPRET_TYPE_INTERPRET_OK);
            break;
    }
}
 
Example #4
Source File: SampleTinkerReport.java    From HotFixDemo with MIT License 6 votes vote down vote up
public static void onLoadFileNotFound(int fileType) {
    if (reporter == null) {
        return;
    }
    switch (fileType) {
        case ShareConstants.TYPE_DEX_OPT:
            reporter.onReport(KEY_LOADED_MISSING_DEX_OPT);
            break;
        case ShareConstants.TYPE_DEX:
            reporter.onReport(KEY_LOADED_MISSING_DEX);
            break;
        case ShareConstants.TYPE_LIBRARY:
            reporter.onReport(KEY_LOADED_MISSING_LIB);
            break;
        case ShareConstants.TYPE_PATCH_FILE:
            reporter.onReport(KEY_LOADED_MISSING_PATCH_FILE);
            break;
        case ShareConstants.TYPE_PATCH_INFO:
            reporter.onReport(KEY_LOADED_MISSING_PATCH_INFO);
            break;
        case ShareConstants.TYPE_RESOURCE:
            reporter.onReport(KEY_LOADED_MISSING_RES);
            break;
    }
}
 
Example #5
Source File: SampleTinkerReport.java    From HotFixDemo with MIT License 6 votes vote down vote up
public static void onLoadInterpretReport(int type, Throwable e) {
    if (reporter == null) {
        return;
    }
    switch (type) {
        case ShareConstants.TYPE_INTERPRET_GET_INSTRUCTION_SET_ERROR:
            reporter.onReport(KEY_LOADED_INTERPRET_GET_INSTRUCTION_SET_ERROR);
            reporter.onReport("Tinker Exception:interpret occur exception " + TinkerUtils.getExceptionCauseString(e));
            break;
        case ShareConstants.TYPE_INTERPRET_COMMAND_ERROR:
            reporter.onReport(KEY_LOADED_INTERPRET_INTERPRET_COMMAND_ERROR);
            reporter.onReport("Tinker Exception:interpret occur exception " + TinkerUtils.getExceptionCauseString(e));
            break;
        case ShareConstants.TYPE_INTERPRET_OK:
            reporter.onReport(KEY_LOADED_INTERPRET_TYPE_INTERPRET_OK);
            break;
    }
}
 
Example #6
Source File: SampleTinkerReport.java    From HotFixDemo with MIT License 6 votes vote down vote up
public static void onLoadFileMisMatch(int fileType) {
    if (reporter == null) {
        return;
    }
    switch (fileType) {
        case ShareConstants.TYPE_DEX:
            reporter.onReport(KEY_LOADED_MISMATCH_DEX);
            break;
        case ShareConstants.TYPE_LIBRARY:
            reporter.onReport(KEY_LOADED_MISMATCH_LIB);
            break;
        case ShareConstants.TYPE_RESOURCE:
            reporter.onReport(KEY_LOADED_MISMATCH_RESOURCE);
            break;
    }
}
 
Example #7
Source File: SampleLoadReporter.java    From tinker-manager with Apache License 2.0 6 votes vote down vote up
@Override
public void onLoadResult(File patchDirectory, int loadCode, long cost) {
    super.onLoadResult(patchDirectory, loadCode, cost);
    switch (loadCode) {
        case ShareConstants.ERROR_LOAD_OK:
            PatchManager.getInstance().onLoadSuccess();
            SampleTinkerReport.onLoaded(cost);
            break;

        default:
            break;
    }
    Looper.getMainLooper().myQueue().addIdleHandler(new MessageQueue.IdleHandler() {
        @Override
        public boolean queueIdle() {
            if (UpgradePatchRetry.getInstance(context).onPatchRetryLoad()) {
                SampleTinkerReport.onReportRetryPatch();
            }
            return false;
        }
    });
}
 
Example #8
Source File: SampleTinkerReport.java    From tinker-manager with Apache License 2.0 6 votes vote down vote up
public static void onLoadFileMisMatch(int fileType) {
    if (reporter == null) {
        return;
    }
    switch (fileType) {
        case ShareConstants.TYPE_DEX:
            reporter.onReport(KEY_LOADED_MISMATCH_DEX);
            break;
        case ShareConstants.TYPE_LIBRARY:
            reporter.onReport(KEY_LOADED_MISMATCH_LIB);
            break;
        case ShareConstants.TYPE_RESOURCE:
            reporter.onReport(KEY_LOADED_MISMATCH_RESOURCE);
            break;
    }
}
 
Example #9
Source File: SampleTinkerReport.java    From HotFixDemo with MIT License 6 votes vote down vote up
public static void onApplyExtractFail(int fileType) {
    if (reporter == null) {
        return;
    }
    switch (fileType) {
        case ShareConstants.TYPE_DEX:
            reporter.onReport(KEY_APPLIED_DEX_EXTRACT);
            break;
        case ShareConstants.TYPE_LIBRARY:
            reporter.onReport(KEY_APPLIED_LIB_EXTRACT);
            break;
        case ShareConstants.TYPE_PATCH_FILE:
            reporter.onReport(KEY_APPLIED_PATCH_FILE_EXTRACT);
            break;
        case ShareConstants.TYPE_RESOURCE:
            reporter.onReport(KEY_APPLIED_RESOURCE_EXTRACT);
            break;
    }
}
 
Example #10
Source File: SampleTinkerReport.java    From tinker-manager with Apache License 2.0 6 votes vote down vote up
public static void onApplyExtractFail(int fileType) {
    if (reporter == null) {
        return;
    }
    switch (fileType) {
        case ShareConstants.TYPE_DEX:
            reporter.onReport(KEY_APPLIED_DEX_EXTRACT);
            break;
        case ShareConstants.TYPE_LIBRARY:
            reporter.onReport(KEY_APPLIED_LIB_EXTRACT);
            break;
        case ShareConstants.TYPE_PATCH_FILE:
            reporter.onReport(KEY_APPLIED_PATCH_FILE_EXTRACT);
            break;
        case ShareConstants.TYPE_RESOURCE:
            reporter.onReport(KEY_APPLIED_RESOURCE_EXTRACT);
            break;
    }
}
 
Example #11
Source File: SampleLoadReporter.java    From HotFixDemo with MIT License 6 votes vote down vote up
/**
 * 这个是无论加载失败或者成功都会回调的接口。
 * 它返回了本次加载所用的时间、返回码等信息。
 * 默认我们只是简单的输出这个信息,你可以在这里加上监控上报逻辑。
 */
@Override
public void onLoadResult(File patchDirectory, int loadCode, long cost) {
    super.onLoadResult(patchDirectory, loadCode, cost);
    switch (loadCode) {
        case ShareConstants.ERROR_LOAD_OK:
            SampleTinkerReport.onLoaded(cost);
            break;
    }
    Looper.getMainLooper().myQueue().addIdleHandler(new MessageQueue.IdleHandler() {
        @Override
        public boolean queueIdle() {
            if (UpgradePatchRetry.getInstance(context).onPatchRetryLoad()) {
               SampleTinkerReport.onReportRetryPatch();
            }
            return false;
        }
    });
}
 
Example #12
Source File: SampleTinkerReport.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
public static void onApplyPackageCheckFail(int errorCode) {
    if (reporter == null) {
        return;
    }
    TinkerLog.i(TAG, "hp_report package check failed, error = %d", errorCode);

    switch (errorCode) {
        case ShareConstants.ERROR_PACKAGE_CHECK_SIGNATURE_FAIL:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_SIGNATURE);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_DEX_META_CORRUPTED:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_DEX_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_LIB_META_CORRUPTED:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_LIB_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_PATCH_TINKER_ID_NOT_FOUND:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_PATCH_TINKER_ID_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_APK_TINKER_ID_NOT_FOUND:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_APK_TINKER_ID_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_TINKER_ID_NOT_EQUAL:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_TINKER_ID_NOT_EQUAL);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_PACKAGE_META_NOT_FOUND:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_META_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_RESOURCE_META_CORRUPTED:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_RES_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_TINKERFLAG_NOT_SUPPORT:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_TINKERFLAG_NOT_SUPPORT);
            break;
    }
}
 
Example #13
Source File: SampleTinkerReport.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
public static void onLoadPackageCheckFail(int errorCode) {
    if (reporter == null) {
        return;
    }
    switch (errorCode) {
        case ShareConstants.ERROR_PACKAGE_CHECK_SIGNATURE_FAIL:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_SIGNATURE);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_DEX_META_CORRUPTED:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_DEX_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_LIB_META_CORRUPTED:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_LIB_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_PATCH_TINKER_ID_NOT_FOUND:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_PATCH_TINKER_ID_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_APK_TINKER_ID_NOT_FOUND:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_APK_TINKER_ID_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_TINKER_ID_NOT_EQUAL:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_TINKER_ID_NOT_EQUAL);

            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_PACKAGE_META_NOT_FOUND:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_PACKAGE_META_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_RESOURCE_META_CORRUPTED:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_RES_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_TINKERFLAG_NOT_SUPPORT:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_TINKERFLAG_NOT_SUPPORT);
            break;
    }
}
 
Example #14
Source File: SampleTinkerReport.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
public static void onLoadException(Throwable throwable, int errorCode) {
    if (reporter == null) {
        return;
    }
    boolean isCheckFail = false;
    switch (errorCode) {
        case ShareConstants.ERROR_LOAD_EXCEPTION_DEX:
            if (throwable.getMessage().contains(ShareConstants.CHECK_DEX_INSTALL_FAIL)) {
                reporter.onReport(KEY_LOADED_EXCEPTION_DEX_CHECK);
                isCheckFail = true;
                TinkerLog.e(TAG, "tinker dex check fail:" + throwable.getMessage());
            } else {
                reporter.onReport(KEY_LOADED_EXCEPTION_DEX);
                TinkerLog.e(TAG, "tinker dex reflect fail:" + throwable.getMessage());
            }
            break;
        case ShareConstants.ERROR_LOAD_EXCEPTION_RESOURCE:
            if (throwable.getMessage().contains(ShareConstants.CHECK_RES_INSTALL_FAIL)) {
                reporter.onReport(KEY_LOADED_EXCEPTION_RESOURCE_CHECK);
                isCheckFail = true;
                TinkerLog.e(TAG, "tinker res check fail:" + throwable.getMessage());
            } else {
                reporter.onReport(KEY_LOADED_EXCEPTION_RESOURCE);
                TinkerLog.e(TAG, "tinker res reflect fail:" + throwable.getMessage());
            }
            break;
        case ShareConstants.ERROR_LOAD_EXCEPTION_UNCAUGHT:
            reporter.onReport(KEY_LOADED_UNCAUGHT_EXCEPTION);
            break;
        case ShareConstants.ERROR_LOAD_EXCEPTION_UNKNOWN:
            reporter.onReport(KEY_LOADED_UNKNOWN_EXCEPTION);
            break;
    }
    //reporter exception, for dex check fail, we don't need to report stacktrace
    if (!isCheckFail) {
        reporter.onReport("Tinker Exception:load tinker occur exception " + SampleUtils.getExceptionCauseString(throwable));
    }
}
 
Example #15
Source File: SampleTinkerReport.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
public static void onApplyDexOptFail(Throwable throwable) {
    if (reporter == null) {
        return;
    }
    if (throwable.getMessage().contains(ShareConstants.CHECK_DEX_OAT_EXIST_FAIL)) {
        reporter.onReport(KEY_APPLIED_DEXOPT_EXIST);
    } else if (throwable.getMessage().contains(ShareConstants.CHECK_DEX_OAT_FORMAT_FAIL)) {
        reporter.onReport(KEY_APPLIED_DEXOPT_FORMAT);
    } else {
        reporter.onReport(KEY_APPLIED_DEXOPT_OTHER);
        reporter.onReport("Tinker Exception:apply tinker occur exception " + SampleUtils.getExceptionCauseString(throwable));
    }
}
 
Example #16
Source File: SampleUncaughtExceptionHandler.java    From HotFixDemo with MIT License 5 votes vote down vote up
/**
 * if tinker is load, and it crash more than MAX_CRASH_COUNT, then we just clean patch.
 */
private boolean tinkerFastCrashProtect() {
    ApplicationLike applicationLike = TinkerManager.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 tinker, 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) + 1;
        if (fastCrashCount >= MAX_CRASH_COUNT) {
            SampleTinkerReport.onFastCrashProtect();
            TinkerApplicationHelper.cleanPatch(applicationLike);
            TinkerLog.e(TAG, "tinker has fast crash more than %d, we just clean patch!", fastCrashCount);
            return true;
        } else {
            sp.edit().putInt(currentVersion, fastCrashCount).commit();
            TinkerLog.e(TAG, "tinker has fast crash %d times", fastCrashCount);
        }
    }

    return false;
}
 
Example #17
Source File: SampleLoadReporter.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #18
Source File: SamplePatchListener.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
/**
 * because we use the defaultCheckPatchReceived method
 * the error code define by myself should after {@code ShareConstants.ERROR_RECOVER_INSERVICE
 *
 * @param path
 * @param newPatch
 * @return
 */
@Override
public int patchCheck(String path, String patchMd5) {
    File patchFile = new File(path);
    TinkerLog.i(TAG, "receive a patch file: %s, file size:%d", path, SharePatchFileUtil.getFileOrDirectorySize(patchFile));
    int returnCode = super.patchCheck(path, patchMd5);

    if (returnCode == ShareConstants.ERROR_PATCH_OK) {
        returnCode = SampleUtils.checkForPatchRecover(NEW_PATCH_RESTRICTION_SPACE_SIZE_MIN, maxMemory);
    }

    if (returnCode == ShareConstants.ERROR_PATCH_OK) {
        SharedPreferences sp = context.getSharedPreferences(ShareConstants.TINKER_SHARE_PREFERENCE_CONFIG, Context.MODE_MULTI_PROCESS);
        //optional, only disable this patch file with md5
        int fastCrashCount = sp.getInt(patchMd5, 0);
        if (fastCrashCount >= SampleUncaughtExceptionHandler.MAX_CRASH_COUNT) {
            returnCode = SampleUtils.ERROR_PATCH_CRASH_LIMIT;
        }
    }
    // Warning, it is just a sample case, you don't need to copy all of these
    // Interception some of the request
    if (returnCode == ShareConstants.ERROR_PATCH_OK) {
        Properties properties = ShareTinkerInternals.fastGetPatchPackageMeta(patchFile);
        if (properties == null) {
            returnCode = SampleUtils.ERROR_PATCH_CONDITION_NOT_SATISFIED;
        } else {
            String platform = properties.getProperty(SampleUtils.PLATFORM);
            TinkerLog.i(TAG, "get platform:" + platform);
            // check patch platform require
            if (platform == null) {
                returnCode = SampleUtils.ERROR_PATCH_CONDITION_NOT_SATISFIED;
            }
        }
    }

    SampleTinkerReport.onTryApply(returnCode == ShareConstants.ERROR_PATCH_OK);
    return returnCode;
}
 
Example #19
Source File: SamplePatchListener.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
@Override
public int onPatchReceived(String path) {

    path = PatchUtils.release(path);

    int returnCode = patchCheck(path, SharePatchFileUtil.getMD5(new File(path)));

    if (returnCode == ShareConstants.ERROR_PATCH_OK) {
        SamplePatchService.runPatchService(context, path);
    } else {
        Tinker.with(context).getLoadReporter().onLoadPatchListenerReceiveFail(new File(path), returnCode);
    }
    return returnCode;

}
 
Example #20
Source File: SampleUtils.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
public static int checkForPatchRecover(long roomSize, int maxMemory) {
    if (SampleUtils.isGooglePlay()) {
        return SampleUtils.ERROR_PATCH_GOOGLEPLAY_CHANNEL;
    }
    if (maxMemory < MIN_MEMORY_HEAP_SIZE) {
        return SampleUtils.ERROR_PATCH_MEMORY_LIMIT;
    }
    //or you can mention user to clean their rom space!
    if (!checkRomSpaceEnough(roomSize)) {
        return SampleUtils.ERROR_PATCH_ROM_SPACE;
    }

    return ShareConstants.ERROR_PATCH_OK;
}
 
Example #21
Source File: SampleUncaughtExceptionHandler.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #22
Source File: MainActivity.java    From HotFixDemo with MIT License 5 votes vote down vote up
public void show_info(View view) {
    // add more Build Info
    final StringBuilder sb = new StringBuilder();
    Tinker tinker = Tinker.with(getApplicationContext());
    if (tinker.isTinkerLoaded()) {
        sb.append(String.format("[patch is loaded] \n"));
        sb.append(String.format("[buildConfig TINKER_ID] %s \n", BuildInfo.TINKER_ID));
        sb.append(String.format("[buildConfig BASE_TINKER_ID] %s \n", BaseBuildInfo.BASE_TINKER_ID));

        sb.append(String.format("[buildConfig MESSSAGE] %s \n", BuildInfo.MESSAGE));
        sb.append(String.format("[TINKER_ID] %s \n", tinker.getTinkerLoadResultIfPresent().getPackageConfigByName(ShareConstants.TINKER_ID)));
        sb.append(String.format("[packageConfig patchMessage] %s \n", tinker.getTinkerLoadResultIfPresent().getPackageConfigByName("patchMessage")));
        sb.append(String.format("[TINKER_ID Rom Space] %d k \n", tinker.getTinkerRomSpace()));

    } else {
        sb.append(String.format("[patch is not loaded] \n"));
        sb.append(String.format("[buildConfig TINKER_ID] %s \n", BuildInfo.TINKER_ID));
        sb.append(String.format("[buildConfig BASE_TINKER_ID] %s \n", BaseBuildInfo.BASE_TINKER_ID));

        sb.append(String.format("[buildConfig MESSSAGE] %s \n", BuildInfo.MESSAGE));
        sb.append(String.format("[TINKER_ID] %s \n", ShareTinkerInternals.getManifestTinkerID(getApplicationContext())));
    }
    sb.append(String.format("[BaseBuildInfo Message] %s \n", BaseBuildInfo.TEST_MESSAGE));

    final TextView v = new TextView(this);
    v.setText(sb);
    v.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
    v.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
    v.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    v.setTextColor(0xFF000000);
    v.setTypeface(Typeface.MONOSPACE);
    final int padding = 16;
    v.setPadding(padding, padding, padding, padding);

    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCancelable(true);
    builder.setView(v);
    final AlertDialog alert = builder.create();
    alert.show();
}
 
Example #23
Source File: TinkerUtils.java    From HotFixDemo with MIT License 5 votes vote down vote up
/**
 * 判断当前是否非GP渠道,且空间足够
 */
public static int checkForPatchRecover(long roomSize, int maxMemory) {
    if (TinkerUtils.isGooglePlay()) {
        return TinkerUtils.ERROR_PATCH_GOOGLEPLAY_CHANNEL;
    }
    if (maxMemory < MIN_MEMORY_HEAP_SIZE) {
        return TinkerUtils.ERROR_PATCH_MEMORY_LIMIT;
    }
    //or you can mention user to clean their rom space!
    if (!checkRomSpaceEnough(roomSize)) {
        return TinkerUtils.ERROR_PATCH_ROM_SPACE;
    }

    return ShareConstants.ERROR_PATCH_OK;
}
 
Example #24
Source File: SamplePatchListener.java    From HotFixDemo with MIT License 5 votes vote down vote up
/**
 * 若检查成功,我们会调用TinkerPatchService.runPatchService唤起:patch进程,去尝试完成补丁合成操作。反之,会回调检验失败的接口。
 * 若检查失败,会在LoadReporter的onLoadPatchListenerReceiveFail中回调。
 * <p>
 * because we use the defaultCheckPatchReceived method
 * the error code define by myself should after {@code ShareConstants.ERROR_RECOVER_INSERVICE
 *
 * @param path
 * @param newPatch
 * @return
 */
@Override
public int patchCheck(String path, String patchMd5) {
    File patchFile = new File(path);
    TinkerLog.i(TAG, "receive a patch file: %s, file size:%d", path, SharePatchFileUtil.getFileOrDirectorySize(patchFile));
    int returnCode = super.patchCheck(path, patchMd5);

    if (returnCode == ShareConstants.ERROR_PATCH_OK) {
        returnCode = TinkerUtils.checkForPatchRecover(NEW_PATCH_RESTRICTION_SPACE_SIZE_MIN, maxMemory);
    }

    if (returnCode == ShareConstants.ERROR_PATCH_OK) {
        SharedPreferences sp = context.getSharedPreferences(ShareConstants.TINKER_SHARE_PREFERENCE_CONFIG, Context.MODE_MULTI_PROCESS);
        //optional, only disable this patch file with md5
        int fastCrashCount = sp.getInt(patchMd5, 0);
        if (fastCrashCount >= SampleUncaughtExceptionHandler.MAX_CRASH_COUNT) {
            returnCode = TinkerUtils.ERROR_PATCH_CRASH_LIMIT;
        }
    }
    // Warning, it is just a sample case, you don't need to copy all of these
    // Interception some of the request
    if (returnCode == ShareConstants.ERROR_PATCH_OK) {
        Properties properties = ShareTinkerInternals.fastGetPatchPackageMeta(patchFile);
        if (properties == null) {
            returnCode = TinkerUtils.ERROR_PATCH_CONDITION_NOT_SATISFIED;
        } else {
            String platform = properties.getProperty(TinkerUtils.PLATFORM);
            TinkerLog.i(TAG, "get platform:" + platform);
            // check patch platform require
            if (platform == null || !platform.equals("all")) {
                returnCode = TinkerUtils.ERROR_PATCH_CONDITION_NOT_SATISFIED;
            }
        }
    }

    SampleTinkerReport.onTryApply(returnCode == ShareConstants.ERROR_PATCH_OK);
    return returnCode;
}
 
Example #25
Source File: SampleTinkerReport.java    From HotFixDemo with MIT License 5 votes vote down vote up
public static void onApplyPackageCheckFail(int errorCode) {
    if (reporter == null) {
        return;
    }
    TinkerLog.i(TAG, "hp_report package check failed, error = %d", errorCode);

    switch (errorCode) {
        case ShareConstants.ERROR_PACKAGE_CHECK_SIGNATURE_FAIL:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_SIGNATURE);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_DEX_META_CORRUPTED:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_DEX_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_LIB_META_CORRUPTED:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_LIB_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_PATCH_TINKER_ID_NOT_FOUND:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_PATCH_TINKER_ID_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_APK_TINKER_ID_NOT_FOUND:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_APK_TINKER_ID_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_TINKER_ID_NOT_EQUAL:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_TINKER_ID_NOT_EQUAL);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_PACKAGE_META_NOT_FOUND:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_META_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_RESOURCE_META_CORRUPTED:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_RES_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_TINKERFLAG_NOT_SUPPORT:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_TINKERFLAG_NOT_SUPPORT);
            break;
    }
}
 
Example #26
Source File: SampleTinkerReport.java    From HotFixDemo with MIT License 5 votes vote down vote up
public static void onApplyDexOptFail(Throwable throwable) {
    if (reporter == null) {
        return;
    }
    if (throwable.getMessage().contains(ShareConstants.CHECK_DEX_OAT_EXIST_FAIL)) {
        reporter.onReport(KEY_APPLIED_DEXOPT_EXIST);
    } else if (throwable.getMessage().contains(ShareConstants.CHECK_DEX_OAT_FORMAT_FAIL)) {
        reporter.onReport(KEY_APPLIED_DEXOPT_FORMAT);
    } else {
        reporter.onReport(KEY_APPLIED_DEXOPT_OTHER);
        reporter.onReport("Tinker Exception:apply tinker occur exception " + TinkerUtils.getExceptionCauseString(throwable));
    }
}
 
Example #27
Source File: SampleTinkerReport.java    From HotFixDemo with MIT License 5 votes vote down vote up
public static void onLoadException(Throwable throwable, int errorCode) {
    if (reporter == null) {
        return;
    }
    boolean isCheckFail = false;
    switch (errorCode) {
        case ShareConstants.ERROR_LOAD_EXCEPTION_DEX:
            if (throwable.getMessage().contains(ShareConstants.CHECK_DEX_INSTALL_FAIL)) {
                reporter.onReport(KEY_LOADED_EXCEPTION_DEX_CHECK);
                isCheckFail = true;
                TinkerLog.e(TAG, "tinker dex check fail:" + throwable.getMessage());
            } else {
                reporter.onReport(KEY_LOADED_EXCEPTION_DEX);
                TinkerLog.e(TAG, "tinker dex reflect fail:" + throwable.getMessage());
            }
            break;
        case ShareConstants.ERROR_LOAD_EXCEPTION_RESOURCE:
            if (throwable.getMessage().contains(ShareConstants.CHECK_RES_INSTALL_FAIL)) {
                reporter.onReport(KEY_LOADED_EXCEPTION_RESOURCE_CHECK);
                isCheckFail = true;
                TinkerLog.e(TAG, "tinker res check fail:" + throwable.getMessage());
            } else {
                reporter.onReport(KEY_LOADED_EXCEPTION_RESOURCE);
                TinkerLog.e(TAG, "tinker res reflect fail:" + throwable.getMessage());
            }
            break;
        case ShareConstants.ERROR_LOAD_EXCEPTION_UNCAUGHT:
            reporter.onReport(KEY_LOADED_UNCAUGHT_EXCEPTION);
            break;
        case ShareConstants.ERROR_LOAD_EXCEPTION_UNKNOWN:
            reporter.onReport(KEY_LOADED_UNKNOWN_EXCEPTION);
            break;
    }
    //reporter exception, for dex check fail, we don't need to report stacktrace
    if (!isCheckFail) {
        reporter.onReport("Tinker Exception:load tinker occur exception " + TinkerUtils.getExceptionCauseString(throwable));
    }
}
 
Example #28
Source File: SampleTinkerReport.java    From HotFixDemo with MIT License 5 votes vote down vote up
public static void onLoadPackageCheckFail(int errorCode) {
    if (reporter == null) {
        return;
    }
    switch (errorCode) {
        case ShareConstants.ERROR_PACKAGE_CHECK_SIGNATURE_FAIL:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_SIGNATURE);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_DEX_META_CORRUPTED:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_DEX_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_LIB_META_CORRUPTED:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_LIB_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_PATCH_TINKER_ID_NOT_FOUND:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_PATCH_TINKER_ID_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_APK_TINKER_ID_NOT_FOUND:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_APK_TINKER_ID_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_TINKER_ID_NOT_EQUAL:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_TINKER_ID_NOT_EQUAL);

            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_PACKAGE_META_NOT_FOUND:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_PACKAGE_META_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_RESOURCE_META_CORRUPTED:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_RES_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_TINKERFLAG_NOT_SUPPORT:
            reporter.onReport(KEY_LOADED_PACKAGE_CHECK_TINKERFLAG_NOT_SUPPORT);
            break;
    }
}
 
Example #29
Source File: SampleResDiffPatchInternal.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
private static boolean patchResourceExtractViaResourceDiff(Context context, String patchVersionDirectory,
                                                           String meta, File patchFile) {
    String dir = patchVersionDirectory + "/" + ShareConstants.RES_PATH + "/";

    if (!extractResourceDiffInternals(context, dir, meta, patchFile, TYPE_RESOURCE)) {
        TinkerLog.w(TAG, "patch recover, extractDiffInternals fail");
        return false;
    }
    return true;
}
 
Example #30
Source File: SampleApplication.java    From Bugly-Android-Demo with Apache License 2.0 4 votes vote down vote up
public SampleApplication() {
    super(ShareConstants.TINKER_ENABLE_ALL, "com.tencent.bugly.hotfix.SampleApplicationLike",
            "com.tencent.tinker.loader.TinkerLoader", false);
}