Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6ca90cc2 authored by zhuw's avatar zhuw
Browse files

fix cannot delete media files in SnapdragonGallery

because of Android Q upgrade, Gallery need to grant
"Gallery" role to edit media files

Change-Id: I5f866d78ca23c8761acf2f9581897adf7fbe0d96
parent de2fe569
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -256,6 +256,7 @@ public abstract class AbstractGalleryActivity extends AbstractPermissionActivity

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mGLRootView.lockRenderThread();
        try {
            getStateManager().notifyActivityResult(
+18 −0
Original line number Diff line number Diff line
@@ -30,10 +30,13 @@ package com.android.gallery3d.app;

import android.Manifest;
import android.app.Activity;
import android.app.role.RoleManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;

import java.util.ArrayList;

@@ -41,6 +44,7 @@ public abstract class AbstractPermissionActivity extends FragmentActivity {

    public static final int PERMISSION_REQUEST_STORAGE = 1;
    private boolean permissionGranted = false;
    private final int REQUEST_GALLERY_ROLE = 1001;

    protected abstract void onGetPermissionsSuccess();
    protected abstract void onGetPermissionsFailure();
@@ -49,6 +53,20 @@ public abstract class AbstractPermissionActivity extends FragmentActivity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestStoragePermission();
        RoleManager roleManager = getSystemService(RoleManager.class);
        if (!roleManager.isRoleHeld(RoleManager.ROLE_GALLERY)) {
            startActivityForResult(roleManager.createRequestRoleIntent(RoleManager.ROLE_GALLERY),
                    REQUEST_GALLERY_ROLE);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_GALLERY_ROLE && Activity.RESULT_CANCELED == resultCode) {
            Toast.makeText(getApplicationContext(),
                    "Granting failed. SnapdragonGallery can't edit media files.",
                    Toast.LENGTH_SHORT).show();
        }
    }

    private void requestStoragePermission() {