10

We've been getting reports of crashes on some devices when a user opens an Activity that calls the location manager's getLastKnownLocation method. We've requested all the required permissions in our application manifest:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Here is the stack trace:

java.lang.RuntimeException: Unable to resume activity {com.projectname/com.projectname.ui.AtmFinderActivity}: java.lang.SecurityException: invalid package name: com.google.android.gms
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
        at android.app.ActivityThread.access$600(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
        at android.os.Handler.dispatchMessage(Handler.java)
        at android.os.Looper.loop(Looper.java)
        at android.app.ActivityThread.main(ActivityThread.java)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
        at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.SecurityException: invalid package name: com.google.android.gms
        at android.os.Parcel.readException(Parcel.java)
        at android.os.Parcel.readException(Parcel.java)
        at android.location.ILocationManager$Stub$Proxy.getLastLocation(ILocationManager.java)
        at android.location.LocationManager.getLastKnownLocation(LocationManager.java)
        at android.privacy.surrogate.PrivacyLocationManager.getLastKnownLocation(PrivacyLocationManager.java)
        at com.projectname.util.LocationUtils.getLastKnownLocation(SourceFile:48)
        at com.projectname.ui.AtmFinderFragment.initMapIfNeeded(SourceFile:401)
        at com.projectname.ui.AtmFinderFragment.onGooglePlayServicesAvailable(SourceFile:187)
        at com.projectname.maps.GoogleMapServicesUtil.getGooglePlayServicesStatus(SourceFile:40)
        at com.projectname.ui.AtmFinderFragment.onResume(SourceFile:149)
        at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:917)
        at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1080)
        at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1062)
        at android.support.v4.app.FragmentManagerImpl.dispatchResume(SourceFile:1820)
        at android.support.v4.app.FragmentActivity.onPostResume(SourceFile:412)
        at com.actionbarsherlock.app.SherlockFragmentActivity.onPostResume(SourceFile:69)
        at android.app.Activity.performResume(Activity.java)
        ... 13 more

Here is the relevant method from LocationUtils:

public static Location getLastKnownLocation(Context context) {
    if (context != null) {
        LocationManager lm = (LocationManager) context.getSystemService(
                Context.LOCATION_SERVICE);

        // Get our last known location
        Location location = lm.getLastKnownLocation(
                LocationManager.NETWORK_PROVIDER);
        if (location == null) {
            location = lm.getLastKnownLocation(
                    LocationManager.GPS_PROVIDER);
        }
        return location;
    }
    return null;
}

We've been unable to reproduce this issue on any device we have on hand. Has anyone encountered this problem before?

twaddington
  • 11,607
  • 5
  • 35
  • 46
  • 3
    This is just speculation, but that smells like a custom ROM having some kind of issue with Google Play Services to me. I'd dig further into the devices you're having issues with, what are they, what Android revs are they running, and do they have some kind of custom ROM or other customization that's interfering with Google Play? – Charlie Collins Apr 23 '13 at 18:51
  • @CharlieCollins agreed. Most of the devices we've seen with this issue are Galaxy Nexus' running Android 4.2.2. I don't yet have any information about the specific build they're running. – twaddington Apr 23 '13 at 22:06
  • 1
    We are seeing this issue too and it looks like it's due to a custom ROM. – Ian G. Clifton May 14 '13 at 18:16
  • @IanG.Clifton can you elaborate? What have you seen that makes you think so? Would love to get my hands on the build these people are using so I can engineering work around. – twaddington May 16 '13 at 04:22
  • Do you tried using `` permission for network provider. – Oam May 16 '13 at 13:20
  • @Oam thanks, but we have already specified that permission. You'll also note that the stack trace references "invalid package name: com.google.android.gms" and does not mention a permission error. – twaddington May 17 '13 at 06:35
  • 1
    @twaddington When our app was first rolling out, we had a support email from someone saying the app crashed on launch every time on his custom 4.2.2 ROM. The timing and frequency of the crashes lined up with that user and that crash is the one you're seeing. Unfortunately, that user didn't respond to emails for further details :( – Ian G. Clifton May 21 '13 at 00:52
  • possible duplicate of [java.lang.SecurityException: invalid package name: com.google.android.gms](http://stackoverflow.com/questions/20474761/java-lang-securityexception-invalid-package-name-com-google-android-gms) – Jorgesys Dec 17 '13 at 17:45

2 Answers2

0

seem to me like you could prevent it by using require feature

Ofek Ron
  • 8,354
  • 13
  • 55
  • 103
0

Check this out. Here I have implemented methods for find last known gps and last known network locations. https://github.com/thamaranga/GpsNew2/tree/master/GpsNew2