Android 4.4:java.lang.securityexception:package com.android.settings does not belong to 1001

Source: Internet
Author: User

Problem Description:

In the Android4.4.2 above custom-made things, today code base changed to Android4.4.4.

After the code merge to the new Android 4.4.4 code base, the clean build will report the following error:

1W/DALVIKVM (3125): Threadid=1:thread exiting with uncaught exception (GROUP=0X415E8D58)2W/appops (1053): BadPager: Specified package com.android.settings under UID 1001 but it's really 10003E/androidruntime (3125): FATAL exception:main4E/androidruntime (3125): Process:com.android.phone, pid:31255E/androidruntime (3125): Java.lang.SecurityException:Package com.android.settings does notBelong to 10016E/androidruntime (3125): at Android.os.Parcel.readException (parcel.java:1465)7E/androidruntime (3125): at Android.database.DatabaseUtils.readExceptionFromParcel (databaseutils.java:185)8E/androidruntime (3125): at Android.database.DatabaseUtils.readExceptionFromParcel (databaseutils.java:137)9E/androidruntime (3125): at Android.content.ContentProviderProxy.Pager(contentprovidernative.java:636)TenE/androidruntime (3125): at Android.provider.settings$namevaluecache.putstringforuser (Settings.java:903) OneE/androidruntime (3125): at Android.provider.settings$system.putstringforuser (settings.java:1169) AE/androidruntime (3125): at Android.provider.settings$system.putintforuser (settings.java:1274) -E/androidruntime (3125): at Android.provider.settings$system.putint (settings.java:1268) -E/androidruntime (3125): at Com.android.settings.dataroamingsettings$3.onpreferencechange ( dataroamingsettings.java:136) the。。。

Navigate to code, which is the line:

Settings.System.putInt (Getcontentresolver (), Data_roaming_selection_code, 0);

Search for information on the Internet, only to find a relevant introduction:

Http://blog.csdn.net/eqiang8271/article/details/39576101

How to check:

When enable flight mode, it'll update one attribute in the setting ' s DB. When updating the value, security error occurs, saying ' package com.android.settings does ' belong to 1001 '. From the error information, We understand then the user ID which is accessing the DB are 1001 (phone) while the package whic H it belonged to was com.android.settings and in the manifest it's declared that it's the "system" GR OUP, the value is 1000). From Android4.3, there is the permission management module called AppOps, it would check if the process ID and the ID which The package belongs to was identical in case of the application is hacked. In this case, it detected they is different, so the FC occurred.

Tracing the code to Appopsmanager.java, it call Checkpackage (), and then the appopssevice.checkpackage is called. In the This function,

Pkguid = Mcontext.getpackagemanager (). Getpackageuid (PackageName, Userhandle.getuserid (UID));

The returned PACKAGEUID is 1001, and not same as the which of the UID of com.android.settings.

But as a process in System group, the operation which an activity in "phone" process should is valid, since in the Context Impl.java

if (Ainfo.uid = = Process.system_uid && ainfo.uid! = Process.myuid ()) {

Special Case:system-themselves to be loaded

Processes. For purposes of apps ops, we must then consider the context as

Belonging to the "This" process, not the system itself, otherwise

The Package+uid verifications in App ops would fail.

Moppackagename = Activitythread.currentpackagename ();

} else {

Moppackagename = Mbasepackagename;

}


So it's really strange that this case have been considered in the code, but it doesn ' t work after checking the code careful Ly, We found that the init of the Contentresolver is before the code sniff mentioned above. At that time, the moppackagename are not set at all. The solution for this is moving the code of initiating the Contentresolve after initiating moppackagename.

....

} else {

Moppackagename = Mbasepackagename;

}

}

Mcontentresolver = new Applicationcontentresolver (this, mainthread, user);



After changing this, we were wondering why the this error was found till now since it was from AOSP4.4. After checking the settings of AOSP4.4, it won "T access DB when enable/disable flight mode. Accessing DB when Enable/disable flight mode is QUALCOMM specified. That's why the issue happened on the Nokia phone is not AOSP.

To summarize, it means that Android native should not have a problem, but Qualcomm's code base will have this problem.

Here's how to modify it:

Modify Linux/android/frameworks/base/core/java/android/app/contextimpl.java

Place the Mcontentresolver initialization section behind the Moppackagename:

The following sentence

Mcontentresolver = new Applicationcontentresolver (this, mainthread, user);

Put it in the last part of the method:

    if(Container! =NULL) {Mbasepackagename=Container.mbasepackagename; Moppackagename=Container.moppackagename; } Else{mbasepackagename=Packageinfo.mpackagename; ApplicationInfo Ainfo=Packageinfo.getapplicationinfo (); if(Ainfo.uid = = Process.system_uid && Ainfo.uid! =Process.myuid ()) {                //Special Case:system-themselves to be loaded//processes. For purposes of apps ops, we must then consider the context as//Belonging to the "This" process, not the system itself, otherwise//The Package+uid verifications in App ops would fail.Moppackagename =Activitythread.currentpackagename (); } Else{moppackagename=Mbasepackagename; }        }    //Kunkka ModifiedMcontentresolver =NewApplicationcontentresolver ( This, Mainthread, user);

Recompile code, the problem does not appear again.

Android 4.4:java.lang.securityexception:package com.android.settings does not belong to 1001

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.