Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing exception to parcel in signed application

I am experimenting quite a strange behaviour in my Android app and have not been able to find a solution in Stackoverflow or whatever place.

I have an Android application working properly with no error when loaded from Eclipse to the mobile phone. But when signed I am seeing this errors in Logcat:

E/DatabaseUtils(2360): Writing exception to parcel
E/DatabaseUtils(2360): java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
E/DatabaseUtils(2360):  at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
E/DatabaseUtils(2360):  at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
E/DatabaseUtils(2360):  at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
E/DatabaseUtils(2360):  at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
E/DatabaseUtils(2360):  at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
E/DatabaseUtils(2360):  at android.os.Binder.execTransact(Binder.java:388)
E/DatabaseUtils(2360):  at dalvik.system.NativeStart.run(Native Method)

and after that:

E/Parcel(2360): Class not found when unmarshalling: com.meapp.utilites.Anuncio
E/Parcel(2360): java.lang.ClassNotFoundException: com.meapp.utilites.Anuncio
E/Parcel(2360):     at java.lang.Class.classForName(Native Method)
E/Parcel(2360):     at java.lang.Class.forName(Class.java:204)
E/Parcel(2360):     at java.lang.Class.forName(Class.java:169)
E/Parcel(2360):     at android.os.Parcel.readParcelableCreator(Parcel.java:2091)
E/Parcel(2360):     at android.os.Parcel.readParcelable(Parcel.java:2055)
E/Parcel(2360):     at android.os.Parcel.readValue(Parcel.java:1971)
E/Parcel(2360):     at android.os.Parcel.readMapInternal(Parcel.java:2255)
E/Parcel(2360):     at android.os.Bundle.unparcel(Bundle.java:223)
E/Parcel(2360):     at android.os.Bundle.getString(Bundle.java:1082)
E/Parcel(2360):     at android.content.Intent.getStringExtra(Intent.java:4961)
E/Parcel(2360):     at com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:3761)
E/Parcel(2360):     at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:4977)
E/Parcel(2360):     at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3173)
E/Parcel(2360):     at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3129)
E/Parcel(2360):     at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:157)
E/Parcel(2360):     at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2125)
E/Parcel(2360):     at android.os.Binder.execTransact(Binder.java:388)
E/Parcel(2360):     at dalvik.system.NativeStart.run(Native Method)
E/Parcel(2360): Caused by: java.lang.NoClassDefFoundError: com/meapp/utilites/Anuncio
E/Parcel(2360):     ... 18 more
E/Parcel(2360): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.meapp.utilites.Anuncio" on path: .
E/Parcel(2360):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64)
E/Parcel(2360):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/Parcel(2360):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/Parcel(2360):     ... 18 more

I am using proguard with my application and I added these lines to ensure that com.meapp.utilites.Anuncio is visible:

-keep class com.meapp.utilites.** { *; }
-keep class * implements android.os.Parcelable { *; }
-keep public class com.meapp.utilites.Anuncio

com.meapp.utilites.Anuncio implements Parcelable.

But the most extrange thing to me is that even after a ClassNotFoundException not "catched" the app works properly. Even more, the app is doing it work like the Parcelable was recovered without problems because it uses the data contained in that object.

So I have a couple of questions:

  1. Why is giving me a Permission denial in my signed application but there's not problem in the unsigned one?

  2. Why not is crashing my app after a ClassNotFound...?

  3. Why is working properly but announcing that error?

  4. How can I solve this and make proguard make my class visible?

Thanks for your help, I think this a question for Android Ninjas...

like image 647
Jose Luis Martín Romera Avatar asked Jun 24 '14 22:06

Jose Luis Martín Romera


2 Answers

I had this problem 6 months ago so I had to search in bitbucket to see what I changed to make it work.

What I did was change my script proguard-project.txt using this template as a base:

# Basic Template extracted from http://wiebe-elsinga.com/blog/obfuscating-for-android-with-proguard/
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * implements android.os.Parcelable {
    static android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

You can find more info in http://wiebe-elsinga.com/blog/obfuscating-for-android-with-proguard/

As you can see, related to the Parcelable, my original script missed some part of the configuration:

-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}

I hope this helps to all of you @AtulOHolic & @OneWay

like image 113
Jose Luis Martín Romera Avatar answered Sep 18 '22 06:09

Jose Luis Martín Romera


android.permission.INTERACT_ACROSS_USERS_FULL is a signature level permission. Your app will not be able to use it until and unless it has the same signature as the system.

class not found may be due to package problem , make sure that you have given same package name of launching activity as of package name.

hope this will help

like image 41
Sukhbir Avatar answered Sep 20 '22 06:09

Sukhbir