RecoverySystem.installPackage java.lang.NullPointerException

1k views Asked by At

I'm playing with AOSP, and trying to apply OTA package

1). I built AOSP for Google Pixel and installed it

2). I created simple app, which downloads OTA package, and trying to apply it (It's based on this article: http://jhshi.me/2013/12/13/how-to-apply-downloaded-ota-package/index.html)

I'm calling RecoverySystem.installPackage(getContext(), file);, and it gets me

java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.os.IRecoverySystem.setupBcb(java.lang.String)' on a null object reference
    at android.os.RecoverySystem.setupBcb(RecoverySystem.java:895)
    at android.os.RecoverySystem.installPackage(RecoverySystem.java:496)
    at android.os.RecoverySystem.installPackage(RecoverySystem.java:421)

Can anyone point me how to fix it please?

2

There are 2 answers

0
Olaia On

As far as I can see, your error comes from this piece of code:

In RecoverySystem.java:

RecoverySystem rs = (RecoverySystem) context.getSystemService(
                Context.RECOVERY_SERVICE);
if (!rs.setupBcb(command)) {
    throw new IOException("Setup BCB failed");
}

....

/**
 * Talks to RecoverySystemService via Binder to set up the BCB.
 */
private boolean setupBcb(String command) {
    try {
        return mService.setupBcb(command);
    } catch (RemoteException unused) {
    }
    return false;
}

In the first piece of code, the if evaluation, your error is rs has it's mService member as null. Which is used in the ''setupBcb` method. So it looks like the context you are using does NOT have Context.RECOVERY_SERVICE reachable somehow.

Are you using activity context? I would git Application Context a try.

0
Phyo On

This is an old thread but I had the exact same issue on Android 7.1 even after setting the required permissions and putting the apk file in /system/app/myapp. I solved it by adding this line to the AndroidManifest.xml.

android:sharedUserId="android.uid.system"

And my manifest file is like this -

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.myapp"
    android:sharedUserId="android.uid.system"
    tools:ignore="GoogleAppIndexingWarning">