Git Product home page Git Product logo

grant's People

Contributors

anthonycr avatar mengdd avatar tony---zhang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grant's Issues

hasAllPermissions

Shouldn't PermissionsManager.hasPermission method condsider the fix you have made about old versions of Android ? Change log was : Fixed bug where new permissions requested on old Android versions were denied (optional method can change this).

Difference between "new HashSet<>(1)" with "new HashSet<>()"?

I noticed that you used the new HashSet<>(1) instead of new HashSet<>() to initialize a HashSet,is there any profits by doing that?

I read the source code and find that new HashSet<>(1) or new HashSet<>() neither really initialize a HashMapEntry array,it's initialized when method V put(K,V) was first called by void inflateTable(int size).

AM I WRONG OR MISSED?

PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult is not working properly

I am trying to do:

PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(getActivity(),
                            new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, new PermissionsResultAction() {

                                @Override
                                public void onGranted() {
                                    Intent taskPicturesStarter = new Intent(getActivity(), TaskPicturesActivity.class);
                                    taskPicturesStarter.putExtra(ActivityHelper.KEY_TASK_MODEL, mTaskModel);
                                    startActivityForResult(taskPicturesStarter, DATE_TIME_PICKER_ACTIVITY_CODE);
                                }

                                @Override
                                public void onDenied(String permission) {
                                    Toast.makeText(getActivity(),
                                            "Sorry, we need the Storage Permission to do that",
                                            Toast.LENGTH_SHORT).show();
                                }
                            });

But onGranted or onDenied method are not executing.

In the fragment i have also included:


@Override
    public void onRequestPermissionsResult(int requestCode,
                                           @NonNull String[] permissions,
                                           @NonNull int[] grantResults) {
        PermissionsManager.getInstance().notifyPermissionsChange(permissions, grantResults);
    }

I have also tried reinstalling the app but still same problem.

Overload hasAllPermissions

I was thinking on a variation of PermissionsManager.hasAllPermissions that only takes a context and retrieves all the app permissions out of the package info, just like PermissionsManager.requestAllManifestPermissionsIfNecessary

Just by looking at the code, it could be something like the following

public static boolean hasAllPermissions( @Nullable Context context ) { 
    if (context == null) {
        return false;
    }
    PackageInfo packageInfo = null;
    try {
        Log.d(TAG, context.getPackageName());
        packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "A problem occurred when retrieving permissions", e);
    }
    boolean hasAllPermissions = false;
    if (packageInfo != null) {
        hasAllPermissions = true;
        String[] permissions = packageInfo.requestedPermissions;
        if (permissions != null) {
            for (String perm : permissions) {
                hasAllPermissions &= ActivityCompat.checkSelfPermission(context, perm)
                    == PackageManager.PERMISSION_GRANTED;
            }
        }
    }
    return hasAllPermissions;
}

Disclaimer: I have not tested the code nor even compiled it, this is just an idea. I will be happy to contribute properly if the idea is good enough.

Thanks

How can we test android permission?

  1. Why PermissionsManager class use final. In my point of view, I think no class will inherit the Manager class. If they inherit it, the developer have the duty to make sure his/her inherited class can work in right way.
    Another reason is that:
    We can not test it(Mock it).

Reference:
#7

  1. Before android M, why we test android device has the permission or not?

内存泄漏( Memory leak)

PermissionsManager.java
private final List mPendingActions = new ArrayList<>(1);
PermissionsResultAction.java
private final Set mPermissions = new HashSet<>(1);
我不会说中文,我不说了

PermissionManager's PermissionsResultAction List needs to WeakReference its elements

Right now, as it is written, your current PermissionsResultAction list is creating strong references to said elements. This creates issues in that when creating an anonymous callback from an Activity, it implicitly creates a reference to that Activity (according to your example). As a result, it prevents it from garbage collection, until it is eventually removed from that list.

This problem is further compounded if one were to change the device's orientation multiple times, creating multiple adds from previous Activity instances, thus keeping strong refs to them, and thus leaking memory heavily.

My suggestion would be to wrap each PermissionsResultAction element in your List as a WeakReference:

private final List<WeakReference<PermissionsResultAction>> mPendingActions = new ArrayList<>(1);

Then, when adding new actions, you would simply do the following:

mPendingActions.add(new WeakReference<PermissionsResultAction>(action));

And finally, when calling back to them, you would simply check if there's currently a valid reference to them:

while (iterator.hasNext()) {
    final WeakReference<PermissionsResultAction> callbackRef = iterator.next();
    final PermissionsResultAction callback= callbackRef.get();
    if (callback != null && callback.onResult(permissions[n], results[n])) {
        iterator.remove();
    }
    mPendingRequests.remove(permissions[n]);
}

As a result, you create a clean break from your observers that may otherwise not exist when it comes time to call them, and enable their references to get GC'd quickly.

Note that iterator block was my best guess in handling when to remove that Iterator's element given this new model. You may have to polish it slightly to determine when it gets removed given the valid state of a callback reference.

Weakreference of actions list meets unexpected GC

In my use of grant, I met a problem that, when user spend more than 10 seconds or more time to decide whether to give the permission, references in the action list will be GCed, actions get from iterator will return null and will be removed from the list. In that situation, no followed code will be executed, callbacks will NEVER be executed.

For the case, I changed the weakreference list to strong reference objects list as an alternative way, thus suffered from memory leaked risk, but it just worked fine for me and infact you do not have that much dangerous permissions to gain permission.

Hope for a more memory safe way to handle this problem.

onGrant method not working

I am trying to implement following code in my app -

PermissionsManager.getInstance().requestAllManifestPermissionsIfNecessary(this,
new PermissionsResultAction() {
@OverRide
public void onGranted() {
// Proceed with initialization
proceed();
}

@Override
public void onDenied(String permission) {
  // Notify the user that you need all of the permissions
}

});

But what is happening is proceed() method is not calling after granting all the permissions. onGrant method itself not getting called when I tried to debug the app. Please help to resolve my issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.