Getting UpdateEngine is on a null object reference in AB OTA application

2

I am working on Android_Q. Trying to do AB OTA update from Android application. Have gave necessary information to update engine.

E/MessageQueue-JNI: java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.os.IUpdateEngine.bind(android.os.IUpdateEngineCallback)' on a null object reference

public class MainActivity extends Activity {
     private static final String TAG = "OTAupdate";
 private UpdateEngine mUpdateEngine;
 private final UpdateEngineCallbackImpl
        mUpdateEngineCallback = new UpdateEngineCallbackImpl();
float progress;
int status;
ProgressBar progressBar;
Button startButton, pauseButton, stopButton;
boolean paused;
Context mContext;
  private static String[] getInfo() {
    return new String[]{
            "FILE_HASH=/hcckhsjkchjhkjdhjk=",
            "FILE_SIZE="22112",
            "METADATA_HASH=wFVt2qsadadaddd",
            "METADATA_SIZE=3353"
    };
}
     @Override
     public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    startButton = (Button) findViewById(R.id.btn1);
    pauseButton = (Button) findViewById(R.id.btn2);
    stopButton = (Button) findViewById(R.id.btn3);     
     setupButtonListeners();
   UECallback cb = new UECallback();
    mUpdateEngine = new UpdateEngine();
}
class UpdateEngineCallbackImpl extends UpdateEngineCallback {
    @Override
    public void onStatusUpdate(int status, float percent) {           
    }
    @Override
    public void onPayloadApplicationComplete(int errorCode) {          
        Log.d(TAG,"onPayloadApplicationComplete");

    }
}

@Override
public void onStart() {
    super.onStart();

}

@Override
public void onRestart() {
    super.onRestart();
}


@Override
public void onPause() {
    super.onPause();
}

@Override
public void onStop() {
    super.onStop();
}

private class UECallback extends android.os.UpdateEngineCallback {
    public void onStatusUpdate(int aStatus, float aPercent) {
        progress = aPercent * 100;
        status = aStatus;
        progressBar.setProgress(Math.round(progress), true);
        Log.e(TAG, "current progress is" + (int) progress+"--status--"+aStatus);

    }

    public void onPayloadApplicationComplete(int errCode) {
        Log.e(TAG, "Payload application complete, error:" + Integer.toString(errCode));

        if (errCode == 0) {
            Log.e(TAG, "Installation succeeded!");
        }
    }
}

private void setupButtonListeners() {
    startButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.e(TAG, "####### start clicked");
           mUpdateEngine.bind(new UpdateEngineCallback() {
                @Override
                public void onStatusUpdate(int i, float v) {

                }

                @Override
                public void onPayloadApplicationComplete(int i) {

                }
            });      
     mUpdateEngine.applyPayload("file:///data/ota_package/payload.bin",0, 22112,getInfo());

        }
    });

    pauseButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.e(TAG, "###### pause clicked");
            if (paused) {
                paused = false;
                mUpdateEngine.resume();
                pauseButton.setText("resume");
                return;
            }

            paused = true;
            pauseButton.setText("pause");
            mUpdateEngine.suspend();
        }
    });

    stopButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.e(TAG, "###### stop clicked");
            mUpdateEngine.cancel();
            paused = false;

        }
    });

}

}

but getting below error :

  java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.os.IUpdateEngine.bind(android.os.IUpdateEngineCallback)' on a null object reference

Full error log:

(standard input):4838:05-13 09:50:48.563  3590  6403 I ActivityTaskManager: START u0 
{act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 
pkg=com.example.android.systemupdatersample 
cmp=com.example.android.systemupdatersample/.ui.MainActivity} from uid 1000
(standard input):4844:05-13 09:50:48.708  3590  3629 I ActivityManager: Start proc 
6998:com.example.android.systemupdatersample/u0a58 for activity 
{com.example.android.systemupdatersample/com.example.android.systemupdatersample.ui.MainActivity}
(standard input):4864:05-13 09:50:49.189  6998  6998 E AndroidRuntime: Process: 
com.example.android.systemupdatersample, PID: 6998
(standard input):4865:05-13 09:50:49.189  6998  6998 E AndroidRuntime: java.lang.RuntimeException: 
Unable to start activity 
   ComponentInfo
   {com.example.android.systemupdatersample/com.example.android.systemupdatersample.ui.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'boolean 
  android.os.IUpdateEngine.bind(android.os.IUpdateEngineCallback)' on a null object reference
  standard input):4881:05-13 09:50:49.189  6998  6998 E AndroidRuntime:  at 
  com.example.android.systemupdatersample.ui.MainActivity.onCreate(MainActivity.java:110)
  (standard input):4887:05-13 09:50:49.195  3590  6403 W ActivityTaskManager:   Force finishing activity 
  com.example.android.systemupdatersample/.ui.MainActivity
  (standard input):4903:05-13 09:50:49.290  3590  6914 I ActivityManager: Process 
  com.example.android.systemupdatersample (pid 6998) has died: vis+99 TOP
  (standard input):4912:05-13 09:50:49.697  3590  3622 W ActivityTaskManager: Activity top resumed state 
   loss timeout for ActivityRecord{462c162 u0 com.example.android.systemupdatersample/.ui.MainActivity t-1 f}
android
ota
asked on Stack Overflow May 14, 2020 by Kumar • edited May 14, 2020 by Kumar

1 Answer

0

So your bind is failing, this could have several causes:

  1. Your update_engine service is not running in Android. I've found that the update_engine service does not appear to be working on some Emulators. To check the update_engine service using adb shell you can search for the service:
ucm_imx8m_mini:/ ps -A | grep update
root          2917     1   23004   8812 SyS_epoll_wait      0 S update_engine

You can also verify that the update_engine_client command can connect/bind to the service:

    ucm_imx8m_mini:/ update_engine_client --follow                                                                                                                                                
    [INFO:update_engine_client_android.cc(90)] onStatusUpdate(UPDATE_STATUS_IDLE (0), 0)
  1. Your app isn't signed as a system app and therefore can't access the service.

  2. Your app's manifest doesn't specify the system sharedUserID property, e.g.

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.horizonemb.simplesystemapp"
        android:sharedUserId="android.uid.system">
    ...
    </manifest>

If none of these work, do check the With the privileged system permissions section of Google's updater_sample example.

answered on Stack Overflow May 16, 2020 by Donal M

User contributions licensed under CC BY-SA 3.0