Does the V2 Maps Library require the ACCESS_NETWORK_STATE permission?
Asked Answered
D

2

12

I'm using the Android V2 Google Maps Library (Google Play Services) in my published app. I've been seeing sporadic exceptions show up in Google Play that seem to suggest the support map fragment occasionally tries to check the network state. However, the library documentation does not mention that this permission is required. I don't check the network state directly in my application, so I did not declare this permission. As a result a SecurityException is sometimes thrown when inflating the support map fragment:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.foo/com.foo.ui.TransactionDetailActivity}: android.view.InflateException: Binary XML file line #327: Error inflating class fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    at android.app.ActivityThread.access$600(ActivityThread.java:141)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5039)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #327: Error inflating class fragment
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:459)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
    at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(SourceFile:119)
    at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SourceFile:262)
    at com.foo.ui.TransactionDetailActivity.onCreate(SourceFile:129)
    at android.app.Activity.performCreate(Activity.java:5104)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
    ... 11 more
Caused by: java.lang.SecurityException: ConnectivityService: Neither user 10106 nor current process has android.permission.ACCESS_NETWORK_STATE.
    at android.os.Parcel.readException(Parcel.java:1425)
    at android.os.Parcel.readException(Parcel.java:1379)
    at android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:623)
    at android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:425)
    at maps.bm.e.e(Unknown Source)
    at maps.bm.e.a(Unknown Source)
    at maps.z.ag.a(Unknown Source)
    at maps.z.ag.a(Unknown Source)
    at maps.z.ag.a(Unknown Source)
    at maps.z.bw.a(Unknown Source)
    at maps.z.r.onCreateView(Unknown Source)
    at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:107)
    at android.os.Binder.transact(Binder.java:310)
    at com.google.android.gms.maps.a.l.a(Unknown Source)
    at com.google.android.gms.maps.m.a(Unknown Source)
    at com.google.android.gms.internal.ap.a(Unknown Source)
    at com.google.android.gms.internal.al.a(Unknown Source)
    at com.google.android.gms.internal.al.a(Unknown Source)
    at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
    at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:846)
    at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1061)
    at android.support.v4.app.FragmentManagerImpl.addFragment(SourceFile:1160)
    at android.support.v4.app.FragmentActivity.onCreateView(SourceFile:272)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
    ... 28 more

I have declared the relevant permission in my manifest and will see if that fixes the problem. However, it's concerning that this would only happen on some devices and not others. For example, this has worked fine on our internal test devices and many others. Does anyone have any insight into this mysterious issue? Could it be caused by a proguard error?

Edit 1: This error occurred while using version 2.0.10 (541717-10) of the Google Play Services library.

Deplane answered 28/1, 2013 at 17:30 Comment(9)
I wonder if it is not necessarily certain devices that cause the problem, but certain states? For example, maybe on weird transitions from WiFi to 3G or back? Or maybe only when signal is very spotty? Etc...Testate
It's possible, but they should document the use of that permission if it is required.Deplane
Well, it sure looks from your trace that Maps V2 is calling getActiveNetworkInfo(), and the docs for that method say that it needs ACCESS_NETWORK_STATE.Perissodactyl
@Perissodactyl yeah, I figure it was just overlooked in the documentation. I've submitted an issue for them to look into: code.google.com/p/gmaps-api-issues/issues/…Deplane
The main part that is confusing is why it works in the lab -- I've never needed this permission either. There must be some specific conditions in which they make this call that are not normally seen.Perissodactyl
@Perissodactyl exactly! Hoping someone clarifies in the issue tracker. Wish I had the source to dig through.Deplane
Are you on the latest rev of the "Google Play services" entry in the SDK Manager? Mine shows Rev 4 as being current.Perissodactyl
@Perissodactyl good question. I had the latest version installed (rev 4), but not copied into the project. I just updated the Google Play Services library from version 2.0.10 (541717-10) to 2.0.12 (543433-10) as noted in the library manifest. The only changes were the .jar and the manifest file. We'll see if that will make a difference.Deplane
I also have seen this issue but cannot recreate it.Pencil
D
1

With the latest release of the Google Play Services library the documentation has been updated to indicate this permission is required.

The release notes indicate why this permission is required:

Improved recovery from gaining network connectivity. This fix requires the ACCESS_NETWORK_STATE permission.

Deplane answered 26/2, 2013 at 21:27 Comment(0)
G
0

Yes. Any use of the getActiveNetworkInfo() method will require the network state access permission.

The following line in your Manifest should do the trick:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Gentes answered 7/2, 2013 at 8:5 Comment(1)
Thanks, I already added that permissions to my application and it has solved the problem. I guess the real question is why the mapping library is calling getActiveNetworkInfo when it is not documented as requiring this permission.Deplane

© 2022 - 2024 — McMap. All rights reserved.