弹窗BUG
应用使用requestPermissions申请权限时,系统会弹出一个选择窗口,可进行允许或拒绝,
此窗口中有一个”不再询问“的选择框, ”拒绝”及“允许”的按钮。
遇到一个Bug,单点击“不再询问”,“允许”这个按钮会变灰被禁用。
定位
首先定位代码在哪里,首先通过“不再询问”这个文本找出对应英文
packages/apps/PackageInstaller/res/values-zh-rCN/strings.xml:108: “不再询问”
通过这个“never_ask_again”查找
./packages/apps/PackageInstaller/res/layout/grant_permissions.xml: android:text=“@string/never_ask_again”
<!-- desc_container用于显示请求权限程序的图标perm_desc_root,及请求的权限permission_message -->
<FrameLayout
android:id="@+id/desc_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="18dip"
android:paddingStart="20dip"
android:paddingEnd="16dip">
<include
layout="@layout/permission_description" />
</FrameLayout>
<!-- do_not_ask_checkbox就是 不再询问的选择框 -->
<CheckBox
android:id="@+id/do_not_ask_checkbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="-12dp"
android:minHeight="48dp"
android:text="@string/never_ask_again"
android:textColor="?android:attr/textColorPrimary"
style="?android:attr/textAppearanceSmall"
android:visibility="gone">
</CheckBox>
定位到源码在packages/apps/PackageInstaller文件下
GrantPermissionsActivity是进行权限分配的弹出窗口,通过GrantPermissionsDefaultViewHandler来控制GrantPermissionsActivity的ui视图,按钮的点击事件是通过GrantPermissionsViewHandler.ResultListener接口来处理的,GrantPermissionsActivity实现了该接口
public class GrantPermissionsActivity extends OverlayTouchActivity
implements GrantPermissionsViewHandler.ResultListener {
mViewHandler = new com.android.packageinstaller.permission.ui.handheld
.GrantPermissionsViewHandlerImpl(this, getCallingPackage())
.setResultListener(this);
}
修改BUG
修改packages下代码
diff --git a/apps/PackageInstaller/src/com/android/packageinstaller/permission/ui/handheld/GrantPermissionsViewHandlerImpl.java b/apps/PackageInstaller/src/com/android/packageinstaller/permission/ui/handheld/GrantPermissionsViewHandlerImpl.java
index a372e2c5..41c65b89 100644
--- a/apps/PackageInstaller/src/com/android/packageinstaller/permission/ui/handheld/GrantPermissionsViewHandlerImpl.java
+++ b/apps/PackageInstaller/src/com/android/packageinstaller/permission/ui/handheld/GrantPermissionsViewHandlerImpl.java
@@ -342,7 +342,8 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand
if (mResultListener != null) {
view.performAccessibilityAction(
AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null);
- mResultListener.onPermissionGrantResult(mGroupName, true, false);
+ mResultListener.onPermissionGrantResult(mGroupName, true,
+ mShowDonNotAsk && mDoNotAskCheckbox.isChecked());
}
break;
case R.id.permission_deny_button:
@@ -361,7 +362,7 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand
mActivity.startActivity(intent);
break;
case R.id.do_not_ask_checkbox:
- mAllowButton.setEnabled(!mDoNotAskCheckbox.isChecked());
+ //mAllowButton.setEnabled(!mDoNotAskCheckbox.isChecked());
break;
}
}
作者:帅得不敢出门 谢绝转载