3

I hope you can help. I cannot find any documentation on this anywhere. I am requesting runtime permission in my Android app WRITE_EXTERNAL_STORAGE.

Under Android M this works as expected. I hit 'Allow' and all is fine. Under Android N, clicking 'Allow' kills my app. It doesn't crash, it just stops.

In the logcat it shows

Killing 6599:com.myname.myappname/u0a223 (adj 100): permission grant or revoke changed gids
Force removing ActivityRecord{c834991 u0 com.myname.myappname/.MainActivity t1814}: app died, no saved state
Destroying surface Surface(name=Window{bf01619 u0 com.myname.myappname/com.myname.myappname.MainActivity}) called by com.android.server.wm.WindowStateAnimator.destroySurface:-1 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:-1 com.android.server.wm.WindowState.removeLocked:-1 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:-1 com.android.server.wm.WindowManagerService.removeWindowLocked:-1 com.android.server.wm.WindowManagerService.removeWindowLocked:-1 com.android.server.wm.AppWindowToken.removeAllWindows:-1 com.android.server.wm.AppWindowToken.removeAppFromTaskLocked:-1 

Looking at the Android Source Code I found 'permission grant or revoke changed gids' in PackageManagerService.java

private static final String KILL_APP_REASON_GIDS_CHANGED = "permission grant or revoke changed gids";

And

 final int result = permissionsState.grantRuntimePermission(bp, userId);
        switch (result) {
            case PermissionsState.PERMISSION_OPERATION_FAILURE: {
                return;
            }

            case PermissionsState.PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED: {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        killSettingPackagesForUser(sb, userId, KILL_APP_REASON_GIDS_CHANGED);
                    }
                });

My app code which used to work fine is:

   requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);

And then

 @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {

   if (requestCode == 1) {

       // If request is cancelled, the result arrays are empty.
       if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
             // do stuff 
         }

Can anyone explain to me why the app is being killed? And possibly how to catch it in order to restart the app programmatically?

Steve Marcus
  • 199
  • 1
  • 9
  • For which API level are you checking ? Below `API level 23` it will not ask for run time permission. – Piyush Jan 12 '17 at 07:33
  • My guess is that this is a bug in your device. While your process will be terminated when the user revokes permissions from Settings, it should not be terminated when the user grants permissions, whether triggered by `requestPermissions()` in your app or by Settings. You might try existing code that requests runtime permissions. For example, none of [my book's](https://commonsware.com/Android) sample apps that use runtime permissions (such as [this one](https://github.com/commonsguy/cw-omnibus/tree/master/Permissions/tutorial/finish/RuntimePermTutorial)), show the behavior that you describe. – CommonsWare Jan 12 '17 at 14:30
  • @Piyush Correct. This happens when asking for runtime permission on API level 25. – Steve Marcus Jan 19 '17 at 22:49
  • @CommonsWare yes I think you are correct. The HTC build of Android N has inadvertently been distributed with this bug I believe. Thanks. – Steve Marcus Feb 10 '17 at 05:54
  • You are having the bug on stock Android N, or on custom roms? People report the issue on our custom rom from time to time. Even on stock deodexed I get the issue. Also checked googles sources, found the reason and landed here then. – JayTee Jun 30 '17 at 04:37
  • This is happening in stock Android for API level 25, Nougat 7.1.1 – Paixols Apr 01 '22 at 13:14

0 Answers0