天天看點

1850984: Fix: crash when running am.jar without parameters

fix: crash when running am.jar without parameters

記錄第一次給aosp提代碼哈哈哈​

1850984: Fix: crash when running am.jar without parameters

[email protected][email protected] #2oct 9, 2021 10:43amcrash when running am.jar without parameters

steps to reproduce the problem (including sample code if appropriate).

1.use the following .sh to run am.jar,and without parameters

test.sh

<code>#!/system/bin/sh base=/system export classpath=$base/framework/am.jar exec app_process $base/bin com.android.commands.am.am "$@"</code>

2.the crash is as follows

<code>10-08 21:55:12.475 2698 2698 d androidruntime: calling main entry com.android.commands.am.am 10-08 21:55:12.476 2698 2698 d androidruntime: shutting down vm 10-08 21:55:12.476 2698 2698 e androidruntime: fatal exception: main 10-08 21:55:12.476 2698 2698 e androidruntime: pid: 2698 10-08 21:55:12.476 2698 2698 e androidruntime: java.lang.nullpointerexception: attempt to invoke interface method 'android.os.ibinder android.app.iactivitymanager.asbinder()' on a null object reference 10-08 21:55:12.476 2698 2698 e androidruntime: at com.android.commands.am.am.runamcmd(am.java:141) 10-08 21:55:12.476 2698 2698 e androidruntime: at com.android.commands.am.am.onshowusage(am.java:56) 10-08 21:55:12.476 2698 2698 e androidruntime: at com.android.internal.os.basecommand.run(basecommand.java:52) 10-08 21:55:12.476 2698 2698 e androidruntime: at com.android.commands.am.am.main(am.java:50) 10-08 21:55:12.476 2698 2698 e androidruntime: at com.android.internal.os.runtimeinit.nativefinishinit(native method) 10-08 21:55:12.476 2698 2698 e androidruntime: at com.android.internal.os.runtimeinit.main(runtimeinit.java:399) 10-08 21:55:12.477 2698 2698 e androidruntime: error reporting crash 10-08 21:55:12.477 2698 2698 e androidruntime: java.lang.runtimeexception: bad file descriptor 10-08 21:55:12.477 2698 2698 e androidruntime: at android.os.binderproxy.transactnative(native method) 10-08 21:55:12.477 2698 2698 e androidruntime: at android.os.binderproxy.transact(binderproxy.java:550) 10-08 21:55:12.477 2698 2698 e androidruntime: at android.os.iservicemanager$stub$proxy.checkservice(iservicemanager.java:348) 10-08 21:55:12.477 2698 2698 e androidruntime: at android.os.servicemanagerproxy.getservice(servicemanagernative.java:63) 10-08 21:55:12.477 2698 2698 e androidruntime: at android.os.servicemanager.rawgetservice(servicemanager.java:306) 10-08 21:55:12.477 2698 2698 e androidruntime: at android.os.servicemanager.getservice(servicemanager.java:134) 10-08 21:55:12.477 2698 2698 e androidruntime: at android.app.activitymanager$1.create(activitymanager.java:4558) 10-08 21:55:12.477 2698 2698 e androidruntime: at android.app.activitymanager$1.create(activitymanager.java:4555) 10-08 21:55:12.477 2698 2698 e androidruntime: at android.util.singleton.get(singleton.java:43) 10-08 21:55:12.477 2698 2698 e androidruntime: at android.app.activitymanager.getservice(activitymanager.java:4546) 10-08 21:55:12.477 2698 2698 e androidruntime: at com.android.internal.os.runtimeinit$killapplicationhandler.uncaughtexception(runtimeinit.java:158) 10-08 21:55:12.477 2698 2698 e androidruntime: at java.lang.threadgroup.uncaughtexception(threadgroup.java:1073) 10-08 21:55:12.477 2698 2698 e androidruntime: at java.lang.threadgroup.uncaughtexception(threadgroup.java:1068) 10-08 21:55:12.477 2698 2698 e androidruntime: at java.lang.thread.dispatchuncaughtexception(thread.java:2203) 10-08 21:55:12.477 2698 2698 i process : sending signal. pid: 2698 sig: 9 killed</code>

what happened.

as the crash log shows,<code>attempt to invoke interface method asbinder() on a null object reference</code>

when no args to run am.jar, the code flow is :

<code>mam</code> is not initialized at this time, so process will crash in nre

what you think the correct behavior should be.

<code>mam</code> should be initialize before use, for example, put it in the constructor, instead of initializing in the original <code>onrun()</code> function

don't forget to mention which version of android you're using, and/or which device the problem appears on (model and android version).