2

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?

Aleksandr
  • 4,906
  • 4
  • 32
  • 47
  • I'm noticing the same thing, did you find a resolution? – Alex Oct 27 '17 at 15:18
  • @Alex, yes, but I forget how I solved it. As I remember, there was a problem with permissions. You have to grant permission: `` `` The last one, can be granted to system apps only, as I remember – Aleksandr Oct 30 '17 at 05:38
  • BTW, you can check this useful example: https://github.com/CopperheadOS/platform_packages_apps_Updater This is an internal updater implementation for CopperheadOS – Aleksandr Oct 30 '17 at 06:09
  • 1
    It was a permissions problem for me. If you have a priv-app installed on your device and add a permission then reinstall the app, it won't pick up the new permission. You have to remove the old app and copy the apk over to the priv-app folder and then reinstall from there to get the new permission Thanks for pointing me to the CopperheadOS version @Alexander – Alex Oct 30 '17 at 16:56

2 Answers2

3

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.

Olaia
  • 2,172
  • 25
  • 27
2

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">
Phyo
  • 41
  • 8