Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to install a platform signed app to user space?

I've come across a strange issue in a custom Android build recently? I've had a working ROM for months, and using this ROM I've been able to install platform signed apks to user space (/data/app). Recently, after rebuilding the ROM, I've been unable to install those same apks. Any attempt to install a platform signed app (whether it's via adb install, or pm install) yields the following message:

Failure [INSTALL_FAILED_INVALID_INSTALL_LOCATION]

After digging through the Android source, I found the following relevant code block:

if ((compareSignatures(pkg.mSignatures, s1) == PackageManager.SIGNATURE_MATCH)) {
   Slog.w(TAG, "Cannot install platform packages to user storage");
   mLastScanError = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
   return null;
}

Based on my reading, it seems that installing system applications in user space should never have been allowed. Was the initial case where installing system applications in user space an anomaly? Is it possible to install platform signed applications in user space and if so, how does one do it?

like image 936
Fil Avatar asked Oct 22 '22 20:10

Fil


1 Answers

The situation described above occurred because we have a shared Android build machine (shared within the company). A co-worker switched a Git branch without informing me, and thus we were left with old code in our build space. Switching it back to the correct branch solved the problem. To answer the above question more explicitly, it appears that unless you comment out the following code-block, installing platform signed applications in user space is not possible.

(The class file is /frameworks/base/services/src/com/android/server/pm/PackageManagerService.java);

    if (!pkg.applicationInfo.sourceDir.startsWith(Environment.getRootDirectory().getPath()) &&
            !pkg.applicationInfo.sourceDir.startsWith("/vendor")) {
        Object obj = mSettings.getUserIdLPr(1000);
        Signature[] s1 = null;
        if (obj instanceof SharedUserSetting) {
            s1 = ((SharedUserSetting)obj).signatures.mSignatures;
        }
        if ((compareSignatures(pkg.mSignatures, s1) == PackageManager.SIGNATURE_MATCH)) {
            Slog.w(TAG, "Cannot install platform packages to user storage");
            mLastScanError = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
            return null;
        }
    } 
like image 58
Fil Avatar answered Nov 02 '22 03:11

Fil