Skip to content

Commit

Permalink
调整申请检测
Browse files Browse the repository at this point in the history
  • Loading branch information
goweii committed Sep 21, 2019
1 parent 0d9bfe9 commit 120e9a3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import android.support.v4.app.Fragment;

import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.checker.StandardChecker;
import com.yanzhenjie.permission.option.Option;

import java.lang.reflect.Field;

/**
* 描述:
*
Expand Down Expand Up @@ -50,7 +53,8 @@ public class ContextHolder {
mFragment = fragment;
}

public Option getOption(){
public Option getOption() {
hookAndPermission();
if (mContext != null) {
return AndPermission.with(mContext);
} else if (mActivity != null) {
Expand All @@ -63,7 +67,7 @@ public Option getOption(){
return null;
}

public Context getContext(){
public Context getContext() {
if (mContext != null) {
return mContext;
} else if (mActivity != null) {
Expand All @@ -79,4 +83,22 @@ public Context getContext(){
}
return null;
}

private void hookAndPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
hookAndPermissionDoubleChecker();
}
}

private void hookAndPermissionDoubleChecker() {
try {
Class<?> andPermission = Class.forName("com.yanzhenjie.permission.checker.DoubleChecker");
Field strictChecker = andPermission.getDeclaredField("STRICT_CHECKER");
strictChecker.setAccessible(true);
Object fieldObj = strictChecker.get(null);
strictChecker.set(fieldObj, new StandardChecker());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,17 @@ public RuntimeRequester onGoSetting(RequestInterceptor<String> onGoSetting) {
public RuntimeRequester request(@NonNull RequestListener listener) {
mListener = listener;
findUnGrantedPermissions();
if (mUnGrantedPermissions.peek() == null) {
onSuccess();
return this;
}
onBeforeRequest();
next();
return this;
}

public void onActivityResult(int requestCode) {
if (requestCode == mRequestCode) {
if (mUnGrantedPermissions.peek() == null) {
findUnGrantedPermissions();
}
if (mUnGrantedPermissions.peek() == null) {
onSuccess();
return;
}
if (AndPermission.hasPermissions(mContext, mUnGrantedPermissions.peek())) {
mUnGrantedPermissions.poll();
findUnGrantedPermissions();
if (mUnGrantedPermissions.peek() == null) {
onSuccess();
return;
}
onBeforeRequest();
next();
} else {
if (AndPermission.hasAlwaysDeniedPermission(mContext, mUnGrantedPermissions.peek())) {
onGoSetting();
} else {
onBeenDenied();
}
again();
}
}
}
Expand All @@ -102,12 +82,12 @@ private void findUnGrantedPermissions() {
mUnGrantedPermissions = new LinkedList<>();
}
for (String permission : mAllNeededPermissions) {
if (!AndPermission.hasPermissions(mContext, permission)) {
if (AndPermission.hasPermissions(mContext, permission)) {
mUnGrantedPermissions.remove(permission);
} else {
if (!mUnGrantedPermissions.contains(permission)) {
mUnGrantedPermissions.offer(permission);
}
} else {
mUnGrantedPermissions.remove(permission);
}
}
}
Expand Down Expand Up @@ -195,13 +175,22 @@ public void onAction(List<String> data) {
.onDenied(new Action<List<String>>() {
@Override
public void onAction(final List<String> data) {
next();
again();
}
})
.start();
}

private void next() {
// findUnGrantedPermissions();
if (mUnGrantedPermissions.peek() == null) {
onSuccess();
return;
}
onBeforeRequest();
}

private void again() {
if (mUnGrantedPermissions.peek() == null) {
onSuccess();
return;
Expand Down

0 comments on commit 120e9a3

Please sign in to comment.