Tuesday, May 9, 2017

updates - “Package installer has stopped working” after upgrade to OxygenOS 3.1.4 (Marshmallow)


I have upgraded my (rooted) OnePlus X phone from Oxygen OS 2.2.x to 3.1.4 (dirty upgrade, from Lollipop to Marshmallow).


Since doing that, the settings view crashed with "Unfortunately, Package installer has stopped" when I try to view the permission details for some apps. For example, when I open try to view the permissions for Hangouts (Settings > Apps > Hangouts > permissions), the above dialog appears and the following output is shown in logcat:



AndroidRuntime: FATAL EXCEPTION: main
AndroidRuntime: Process: com.android.packageinstaller, PID: 16689
AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.packageinstaller/com.android.packageinstaller.permission.ui.ManagePermissionsActivity}: java.lang.SecurityException: com.google.android.talk from uid 10100 not allowed to perform WRITE_CONTACTS
AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2493)
AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2576)
AndroidRuntime: at android.app.ActivityThread.access$1000(ActivityThread.java:155)
AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5539)

AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
AndroidRuntime: Caused by: java.lang.SecurityException: com.google.android.talk from uid 10100 not allowed to perform WRITE_CONTACTS
AndroidRuntime: at android.app.AppOpsManager.checkOp(AppOpsManager.java:1521)
AndroidRuntime: at com.android.packageinstaller.permission.model.AppPermissionGroup.create(AppPermissionGroup.java:152)
AndroidRuntime: at com.android.packageinstaller.permission.model.AppPermissionGroup.create(AppPermissionGroup.java:94)
AndroidRuntime: at com.android.packageinstaller.permission.model.AppPermissions.loadPermissionGroups(AppPermissions.java:136)
AndroidRuntime: at com.android.packageinstaller.permission.model.AppPermissions.(AppPermissions.java:66)
AndroidRuntime: at com.android.packageinstaller.permission.ui.handheld.AppPermissionsFragment.onCreate(AppPermissionsFragment.java:105)

AndroidRuntime: at android.app.Fragment.performCreate(Fragment.java:2198)
AndroidRuntime: at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
AndroidRuntime: at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
AndroidRuntime: at android.app.BackStackRecord.run(BackStackRecord.java:793)
AndroidRuntime: at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535)
AndroidRuntime: at android.app.FragmentController.execPendingActions(FragmentController.java:325)
AndroidRuntime: at android.app.Activity.performStart(Activity.java:6305)
AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2456)
AndroidRuntime: ... 9 more


And when I open access Settings > Apps > Gears icon > Access permissions, the Android activity briefly appears and then closes. There is no error dialog, but logcat does show the following error:


AndroidRuntime: FATAL EXCEPTION: AsyncTask #4
AndroidRuntime: Process: com.android.packageinstaller, PID: 19194
AndroidRuntime: java.lang.RuntimeException: An error occurred while executing doInBackground()
AndroidRuntime: at android.os.AsyncTask$3.done(AsyncTask.java:309)
AndroidRuntime: at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
AndroidRuntime: at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:242)
AndroidRuntime: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)

AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
AndroidRuntime: at java.lang.Thread.run(Thread.java:818)
AndroidRuntime: Caused by: java.lang.SecurityException: com.ubercab from uid 10102 not allowed to perform CAMERA
AndroidRuntime: at android.app.AppOpsManager.checkOp(AppOpsManager.java:1521)
AndroidRuntime: at com.android.packageinstaller.permission.model.AppPermissionGroup.create(AppPermissionGroup.java:152)
AndroidRuntime: at com.android.packageinstaller.permission.model.PermissionApps.loadPermissionApps(PermissionApps.java:189)
AndroidRuntime: at com.android.packageinstaller.permission.model.PermissionApps.-wrap0(PermissionApps.java)
AndroidRuntime: at com.android.packageinstaller.permission.model.PermissionApps$PermissionAppsLoader.doInBackground(PermissionApps.java:375)
AndroidRuntime: at com.android.packageinstaller.permission.model.PermissionApps$PermissionAppsLoader.doInBackground(PermissionApps.java:374)
AndroidRuntime: at android.os.AsyncTask$2.call(AsyncTask.java:295)

AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
AndroidRuntime: ... 4 more

Why does this happen, and how can I fix this?



Answer



Both error messages in the question include a message in the following format:



java.lang.SecurityException: [app id] from uid [user id] not allowed to perform [permission id]



I recalled that for the affected apps, I once disabled some permissions using the "App Permissions" feature of OxygenOS 2/Lollipop. In OxygenOS 3/Marshmallow, "App Permissions" has been replaced by Android 6's permission management system. Although the UI disappeared after the upgrade, the backend did not and caused crashes when the settings page attempted to check the permission.



To fix the issues, I cleared some appops permissions, as follows:



  1. On the phone: Enable "USB debugging" (Settings > Developer options > USB debugging).

  2. Connect your phone to your computer (where ADB is installed).

  3. At the computer: Start adb logcat to get a continuous stream of log messages (you can also use Logcat on the phone, but using the computer is easier because you will need the phone's screen space at a later step).

  4. At the computer: Use adb shell to get a shell (root is most likely not needed).


  5. Now repeat the following steps for every app at Settings > Apps:



    • Tap on the app icon to view its settings.


    • If the "Permissions" section is not empty, skip the following steps and continue with the next app (e.g. when it shows "No permissions granted" or "No permissions requested" or a specific permission such as "Location").

    • Otherwise (the "Permission" section is blank), tap on "Permissions".

    • Now you will see “Package installer has stopped working”.


    • Look at the logcat output, and look for the following message:



      java.lang.RuntimeException: Unable to start receiver com.android.packageinstaller.permission.model.PermissionStatusReceiver: java.lang.SecurityException: com.google.android.talk from uid 10100 not allowed to perform WRITE_CONTACTS



      In the examples below, I will use com.google.android.talk as app ID and WRITE_CONTACTS as operation/permission ID.





    • OPTIONAL: First look at the existing operation, in case you want to restore the original value (in this case, the output is "WRITE_CONTACTS: deny"), run the following in adb shell:


      appops get com.google.android.talk WRITE_CONTACTS

      (run "appops" without arguments for more options/help.)




    • Allow the operation, by running the following command in the adb shell (if it does not work, try "allow" instead of "default"):


      appops set com.google.android.talk WRITE_CONTACTS default


    • If you get "No operations", then the permission name is probably different. Run appops get com.google.android.talk (without the specific permission) to see all existing permissions. For example, logcat shows "READ_ICC_SMS", but the actual operation ID as shown by the appops command is "READ_SMS"

    • On your phone, Tap on "Permissions". If it crashes again, repeat the above steps (Look at the logcat output, ...). If it does not crash, the Permissions for the selected app is shown and you can revoke permissions if wanted.




After following all steps, I did not get any "Package installed has stopped working" crashes at the settings menu, and I was also able to use Settings > Apps > Gears icon > Access permissions.


PS: not all appops permissions are problematic. Some of the operations that I did have to allow for some apps are: COARSE_LOCATION, CALL_PHONE, CAMERA, READ_CONTACTS, READ_SMS, RECEIVE_SMS, SEND_SMS, WRITE_CONTACTS. E.g. for Hangouts, denying the following operations does not prevent the settings screen from working: WRITE_SMS, WRITE_WALLPAPER.


No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...