Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Base64 APK path

Tags:

android

Note: already saw this question

Checking the android app location on Oreo emulator, the APK is still installed at /data/app. However, instead of the following format:

/data/app/<package_name> or optionally /data/app/<package_name>-1 

it's now

/data/app/<package_name>-_-<22 chars base 64>

or

/data/app/<package_name>-<some chars>-<22 chars base 64>

Does anyone know anything about this change? I've tried googling, but 'APK android location base64' combinations will yield a sea of unrelated results (or google will ignore the base64 keyword)

A link to a google blog or github commit would be nice. I'd settle for the AOSP general location if anyone knows that. Ideally, I'd like to know why (the change), as well as how (the base64 is generated).

like image 871
Roy Falk Avatar asked Dec 24 '17 07:12

Roy Falk


1 Answers

Since Android Oreo, the install path for APKs has been changed, see: commit or https://android.googlesource.com/platform/frameworks/base/+/android-8.0.0_r36/services/core/java/com/android/server/pm/PackageManagerService.java

When PackageManagerService is trying to find a right path for installing APKs, it is using getNextCodePath(File targetDir, String packageName) method. Before Android Oreo, the code is:

private File getNextCodePath(File targetDir, String packageName) {
    int suffix = 1;
    File result;
    do {
        result = new File(targetDir, packageName + "-" + suffix);
        suffix++;
    } while (result.exists());
    return result;
}

Since Android Oreo, the code has been changed to:

private File getNextCodePath(File targetDir, String packageName) {
    File result;
    SecureRandom random = new SecureRandom();
    byte[] bytes = new byte[16];
    do {
        random.nextBytes(bytes);
        String suffix = Base64.encodeToString(bytes, Base64.URL_SAFE | Base64.NO_WRAP);
        result = new File(targetDir, packageName + "-" + suffix);
    } while (result.exists());
    return result;
}
like image 100
Zhang quaful Avatar answered Sep 23 '22 01:09

Zhang quaful