Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Pre-installing NDK Application

We are trying to pre-install a NDK Application into the /system/app directory. If I open the apk file in a ZIP file manager, the .so file is inside the lib directory. However, when we preinstall the apk file, the apk's .so file is not copied to system/lib directory, causing for the application to fail when we launched it in the device.

Can anyone please tell me what should be set in the Android.mk for the APK file so that the .so file will be extracted from the APK file and copied to system/lib directory? We need to include the application in the system image.

Any feedback will be greatly appreciated.

Thanks, artsylar

like image 289
artsylar Avatar asked Jul 01 '11 10:07

artsylar


1 Answers

I had the same need and after 2 days of heavy research, I came up with a solution to this problem. It is not simple and requires you to be able to modify the Android System code as well.

Basically PackageManagerService prevents system applications to unpack their native binaries (.so files), unless they have been updated. So the only way to fix this is by modifying PMS.java (aptly named since trying to solve this problem put me in a terrible mood).

On the system's first boot, I check every system package for native binaries by writing a isPackageNative(PackageParser.Package pkg) function:

    private boolean isPackageNative(PackageParser.Package pkg) throws IOException {
    final ZipFile zipFile = new ZipFile(pkg.mPath);
    final Enumeration<? extends ZipEntry> privateZipEntries = zipFile.entries();
    while (privateZipEntries.hasMoreElements()) {
        final ZipEntry zipEntry = privateZipEntries.nextElement();
        final String zipEntryName = zipEntry.getName();
        if(true) Log.e(TAG, "    Zipfile entry:"+zipEntryName);
        if (zipEntryName.endsWith(".so")) {
            zipFile.close();
            return true;
        }
    }
    zipFile.close();
    return false;
  }

This function checks every package for a native library and if it has one, I unpack it. PMS does this check in scanPackageLI(....). Search for the following code in the method:

   if (isSystemApp(pkg) && !isUpdatedSystemApp(pkg))

and add the isPackageNative(pkg) check. There are other small modifications required but you'll probably figure it out once you have this direction. Hope it helps!

like image 128
Nikhil Avatar answered Nov 07 '22 03:11

Nikhil