SecUSo / privacy-friendly-netmonitor

Privacy Friendly App that shows active network connections of installed apps.
GNU General Public License v3.0
157 stars 33 forks source link

java.lang.NullPointerException since change of minSDK #20

Open Yonjuni opened 7 years ago

Yonjuni commented 7 years ago
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
    at android.app.ApplicationPackageManager$ResourceName.hashCode(ApplicationPackageManager.java:1898)
    at android.util.ArrayMap.indexOfKey(ArrayMap.java:363)
    at android.util.ArrayMap.get(ArrayMap.java:405)
    at android.app.ApplicationPackageManager.getCachedIcon(ApplicationPackageManager.java:1792)
    at android.app.ApplicationPackageManager.getThemeIconWithBG(ApplicationPackageManager.java:3122)
    at android.app.ApplicationPackageManager.getThemeIconWithBG(ApplicationPackageManager.java:3106)
    at android.app.ApplicationPackageManager.getThemeIconWithBG(ApplicationPackageManager.java:3102)
    at android.app.ApplicationPackageManager.loadUnbadgedItemIcon(ApplicationPackageManager.java:2952)
    at android.app.ApplicationPackageManager.loadItemIcon(ApplicationPackageManager.java:2823)
    at android.content.pm.PackageItemInfo.loadIcon(PackageItemInfo.java:221)
    at android.content.pm.PackageItemInfo.loadIcon(PackageItemInfo.java:207)
    at org.secuso.privacyfriendlynetmonitor.ConnectionAnalysis.Collector.getIcon(Collector.java:368)
    at org.secuso.privacyfriendlynetmonitor.Activities.ExpandableReportAdapter.getGroupView(ExpandableReportAdapter.java:212)
    at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:446)
    at android.widget.AbsListView.obtainView(AbsListView.java:2929)
    at android.widget.ListView.makeAndAddView(ListView.java:1945)
    at android.widget.ListView.fillDown(ListView.java:719)
    at android.widget.ListView.fillFromTop(ListView.java:785)
    at android.widget.ListView.layoutChildren(ListView.java:1735)
    at android.widget.AbsListView.onLayout(AbsListView.java:2723)
    at android.view.View.layout(View.java:17972)
    at android.view.ViewGroup.layout(ViewGroup.java:5814)
    at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:636)
    at android.view.View.layout(View.java:17972)
    at android.view.ViewGroup.layout(ViewGroup.java:5814)
    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
    at android.view.View.layout(View.java:17972)
    at android.view.ViewGroup.layout(ViewGroup.java:5814)
    at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131)
    at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
    at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1375)
    at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:870)
    at android.view.View.layout(View.java:17972)
    at android.view.ViewGroup.layout(ViewGroup.java:5814)
    at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1167)
    at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:852)
    at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:871)
    at android.view.View.layout(View.java:17972)
    at android.view.ViewGroup.layout(ViewGroup.java:5814)
    at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1193)
    at android.view.View.layout(View.java:17972)
    at android.view.ViewGroup.layout(ViewGroup.java:5814)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
    at android.view.View.layout(View.java:17972)
    at android.view.ViewGroup.layout(ViewGroup.java:5814)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
    at android.view.View.layout(View.java:17972)
    at android.view.ViewGroup.layout(ViewGroup.java:5814)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
    at android.view.View.layout(View.java:17972)
    at android.view.ViewGroup.layout(ViewGroup.java:5814)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
    at android.view.View.layout(View.java:17972)
    at android.view.ViewGroup.layout(ViewGroup.java:5814)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
    at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:3116)
    at android.view.View.layout(View.java:17972)
    at android.view.ViewGroup.layout(ViewGroup.java:5814)
    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2669)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2370)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1440)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7421)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
    at android.view.Choreographer.doCallbacks(Choreographer.java:695)
    at android.view.Choreographer.doFrame(Choreographer.java:631)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7230)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Yonjuni commented 7 years ago

Temporary fix is to change the minSDK back to 21.

di72nn commented 7 years ago

Is 06739f67 supposed to be the temporary fix? I ask because the commit doesn't touch the affected if branch.

Yonjuni commented 7 years ago

Yes, it is. The problem is that the service monitoring the connections is only tested for Android 5.0 and 6.0 and there were other problems after downgrading to minSDK 17. If we integrate other versions more testing is required.

di72nn commented 7 years ago

Well, you see, my point is: the commit could not possibly fix this issue. Also, changing minSdkVersion between 17 and 21 could not introduce or fix any bugs on devices with API level >= 21.

Anyway, the error is caused by the method android.app.ApplicationPackageManager$ResourceName.hashCode() which calls hashCode() on null String. In all recent Android versions only this call could cause it: packageName.hashCode();. I'm not aware how packageName could be null there. Ever more: this stuff:

    at android.app.ApplicationPackageManager.getThemeIconWithBG(ApplicationPackageManager.java:3122)
    at android.app.ApplicationPackageManager.getThemeIconWithBG(ApplicationPackageManager.java:3106)
    at android.app.ApplicationPackageManager.getThemeIconWithBG(ApplicationPackageManager.java:3102)

is not present in the sources of any known to me Android version. So it might as well be some ApplicationPackageManager screwed up by OEM.

schillef commented 7 years ago

Since it sould only affect some apps with broken package info (my guess) it sould be catachable in the method. Ive made a pull request and tested it on a 4.x hardware device. But I have no app guaranteed to throw this error.