赞
踩
记一次文件极客安装应用报错问题的分析
测试反馈文件极客手动安装应用时出现报错
复现步骤:
1.预置一个apk文件到手机中
2.文件极客中安装此apk
3.弹窗,文件极客需要安装未知来源应用的权限
4.在设置中打开权限,此时出现报错弹窗
关键log:
04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime: FATAL
EXCEPTION: main 04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime:
Process: com.google.android.packageinstaller, PID: 15485 04-02
10:23:13.988 10048 15485 15485 E AndroidRuntime:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.google.android.packageinstaller/com.android.packageinstaller.PackageInstallerActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method
‘java.lang.String
android.content.pm.PackageInstaller S e s s i o n I n f o . g e t R e s o l v e d B a s e A p k P a t h ( ) ′ o n a n u l l o b j e c t r e f e r e n c e 04 − 0210 : 23 : 13.988100481548515485 E A n d r o i d R u n t i m e : a t a n d r o i d . a p p . A c t i v i t y T h r e a d . p e r f o r m L a u n c h A c t i v i t y ( A c t i v i t y T h r e a d . j a v a : 3823 ) 04 − 0210 : 23 : 13.988100481548515485 E A n d r o i d R u n t i m e : a t a n d r o i d . a p p . A c t i v i t y T h r e a d . h a n d l e L a u n c h A c t i v i t y ( A c t i v i t y T h r e a d . j a v a : 3963 ) 04 − 0210 : 23 : 13.988100481548515485 E A n d r o i d R u n t i m e : a t a n d r o i d . a p p . s e r v e r t r a n s a c t i o n . L a u n c h A c t i v i t y I t e m . e x e c u t e ( L a u n c h A c t i v i t y I t e m . j a v a : 103 ) 04 − 0210 : 23 : 13.988100481548515485 E A n d r o i d R u n t i m e : a t a n d r o i d . a p p . s e r v e r t r a n s a c t i o n . T r a n s a c t i o n E x e c u t o r . e x e c u t e C a l l b a c k s ( T r a n s a c t i o n E x e c u t o r . j a v a : 139 ) 04 − 0210 : 23 : 13.988100481548515485 E A n d r o i d R u n t i m e : a t a n d r o i d . a p p . s e r v e r t r a n s a c t i o n . T r a n s a c t i o n E x e c u t o r . e x e c u t e ( T r a n s a c t i o n E x e c u t o r . j a v a : 96 ) 04 − 0210 : 23 : 13.988100481548515485 E A n d r o i d R u n t i m e : a t a n d r o i d . a p p . A c t i v i t y T h r e a d SessionInfo.getResolvedBaseApkPath()' on a null object reference 04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3823) 04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3963) 04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139) 04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96) 04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime: at android.app.ActivityThread SessionInfo.getResolvedBaseApkPath()′onanullobjectreference04−0210:23:13.988100481548515485EAndroidRuntime:atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:3823)04−0210:23:13.988100481548515485EAndroidRuntime:atandroid.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3963)04−0210:23:13.988100481548515485EAndroidRuntime:atandroid.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)04−0210:23:13.988100481548515485EAndroidRuntime:atandroid.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)04−0210:23:13.988100481548515485EAndroidRuntime:atandroid.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)04−0210:23:13.988100481548515485EAndroidRuntime:atandroid.app.ActivityThreadH.handleMessage(ActivityThread.java:2484)
04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime: at
android.os.Handler.dispatchMessage(Handler.java:106) 04-02
10:23:13.988 10048 15485 15485 E AndroidRuntime: at
android.os.Looper.loopOnce(Looper.java:205) 04-02 10:23:13.988 10048
15485 15485 E AndroidRuntime: at
android.os.Looper.loop(Looper.java:294) 04-02 10:23:13.988 10048 15485
15485 E AndroidRuntime: at
android.app.ActivityThread.main(ActivityThread.java:8225) 04-02
10:23:13.988 10048 15485 15485 E AndroidRuntime: at
java.lang.reflect.Method.invoke(Native Method) 04-02 10:23:13.988
10048 15485 15485 E AndroidRuntime: at
com.android.internal.os.RuntimeInit M e t h o d A n d A r g s C a l l e r . r u n ( R u n t i m e I n i t . j a v a : 573 ) 04 − 0210 : 23 : 13.988100481548515485 E A n d r o i d R u n t i m e : a t c o m . a n d r o i d . i n t e r n a l . o s . Z y g o t e I n i t . m a i n ( Z y g o t e I n i t . j a v a : 1058 ) 04 − 0210 : 23 : 13.988100481548515485 E A n d r o i d R u n t i m e : C a u s e d b y : j a v a . l a n g . N u l l P o i n t e r E x c e p t i o n : A t t e m p t t o i n v o k e v i r t u a l m e t h o d ′ j a v a . l a n g . S t r i n g a n d r o i d . c o n t e n t . p m . P a c k a g e I n s t a l l e r MethodAndArgsCaller.run(RuntimeInit.java:573) 04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1058) 04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.pm.PackageInstaller MethodAndArgsCaller.run(RuntimeInit.java:573)04−0210:23:13.988100481548515485EAndroidRuntime:atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:1058)04−0210:23:13.988100481548515485EAndroidRuntime:Causedby:java.lang.NullPointerException:Attempttoinvokevirtualmethod′java.lang.Stringandroid.content.pm.PackageInstallerSessionInfo.getResolvedBaseApkPath()’
on a null object reference 04-02 10:23:13.988 10048 15485 15485 E
AndroidRuntime: at
com.android.packageinstaller.PackageInstallerActivity.onCreate(PackageInstallerActivity.java:371)
04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime: at
android.app.Activity.performCreate(Activity.java:8595) 04-02
10:23:13.988 10048 15485 15485 E AndroidRuntime: at
android.app.Activity.performCreate(Activity.java:8573) 04-02
10:23:13.988 10048 15485 15485 E AndroidRuntime: at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime: at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3805)
04-02 10:23:13.988 10048 15485 15485 E AndroidRuntime: … 12 more
很明显是一个空指针异常,报错的com.google.android.packageinstaller是Google GMS包中的一个应用,一般我们遇到这类问题都是找Google负责解决的。
但是呢一般Google反馈的时效性都比较差,我们先得排查是否是系统可能的原因导致的。
而且这个问题蛋疼就蛋疼在Google Pixel 8它不复现这个问题,难道真是我们系统的问题?继续分析
这里为空的对象是SessionInfo,源码位置在
/frameworks/base/core/java/android/content/pm/PackageInstaller.java
SessionInfo是其内部类:
3177 /**
3178 * Details for an active install session.
3179 */
3180 public static class SessionInfo implements Parcelable {
OK,此时我们需要弄清楚PackageInstallerActivity中的代码逻辑是咋样的,这个GMS中的应用,我们是没有源代码的,但是可以反编译啊!!!
程序员的事,那叫偷嘛?那叫借!!!
反编译可以看看这篇文章,讲的非常好,这里我不多赘述了。
https://zhuanlan.zhihu.com/p/433259910
看反编译出来的代码:
sessionInfo = this.mInstaller.getSessionInfo(i);
String str1 = sessionInfo.getResolvedBaseApkPath();
sessionInfo = this.mInstaller.getSessionInfo(i);
if (sessionInfo != null) {
String str1 = sessionInfo.getResolvedBaseApkPath();
} else {
paramBundle = null;
}
OK,对比了上面我们反编译完之后的代码,就立马发现问题所在了,出问题的应用源码里竟然缺少了判空代码!!!
此时再回来看看系统的API 这里的@Nullable这个注解,这就是摆明了告诉我们这个方法有可能返回空的啊
731 /**
732 * Return details for a specific session. Callers need to either declare <queries>
733 * element with the specific package name in the app's manifest, have the
734 * android.permission.QUERY_ALL_PACKAGES, or be the session owner to retrieve these details.
735 *
736 * @return details for the requested session, or {@code null} if the session
737 * does not exist.
738 */
739 public @Nullable SessionInfo getSessionInfo(int sessionId) {
740 try {
741 return mInstaller.getSessionInfo(sessionId);
742 } catch (RemoteException e) {
743 throw e.rethrowFromSystemServer();
744 }
745 }
一切水落石出,找Google更新最新apk即可解决问题
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。