Android app cloning prevention for app cloning

An application was created that uses a unique device identifier, which is extracted from the following code fragment

String deviceId = Settings.Secure.getString(getContentResolver(),
            Settings.Secure.ANDROID_ID);

When a user tries to clone an application by cloning an application, he creates a different device identifier and the application cannot work

Is there a way to make our application non-clonable or

Any possible way to have the same device, even if the application instance is cloned?

Is there a way to find out if the application is running in a cloned instance?

+5
source share
1 answer

Applications such as Cloner usually change the package name of the application so that you can get the package name and see if it has changed or not.

if (!context.getPackageName().equals("your.package.name")){
    // close the app or do whatever
}

apk, , , . :

@SuppressLint("PackageManagerGetSignatures")
public static int getCertificateValue(Context ctx){
    try {
        Signature[] signatures = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            try {
                signatures = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNING_CERTIFICATES).signingInfo.getApkContentsSigners();
            }catch (Throwable ignored){}
        }
        if (signatures == null){
            signatures = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
        }
        int value = 1;

        for (Signature signature : signatures) {
            value *= signature.hashCode();
        }
        return value;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}

public static boolean checkCertificate(Context ctx, int trustedValue){
    return getCertificateValue(ctx) == trustedValue;
}

getCertificateValue(context) , , , .

PS: @vladyslav-matviienko, , , . .

0

Source: https://habr.com/ru/post/1693900/


All Articles