Android 11 去掉VPN授权弹窗
前言
在进行Frameworks开发过程中遇到需要客户需要使用VPN进行翻墙,但是在使用的时候总是会有授权弹窗,需要去掉
一、问题解决
1.定位问题
android/frameworks/base/packages/VpnDialogs/src/com/android/vpndialogs/ConfirmDialog.java
2.解决问题
--- a/android/frameworks/base/packages/VpnDialogs/src/com/android/vpndialogs/ConfirmDialog.java
+++ b/android/frameworks/base/packages/VpnDialogs/src/com/android/vpndialogs/ConfirmDialog.java
@@ -53,6 +53,13 @@ public class ConfirmDialog extends AlertActivity
mPackage = getCallingPackage();
mService = IConnectivityManager.Stub.asInterface(
ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
+ // add by ltj 默认授予 vpn权限
+ if (true) {
+ setResult(RESULT_OK);
+ finish();
+ return;
+ }
+ // add by ltj end
if (prepareVpn()) {
setResult(RESULT_OK);
@@ -69,21 +76,23 @@ public class ConfirmDialog extends AlertActivity
finish();
return;
}
- View view = View.inflate(this, R.layout.confirm, null);
- ((TextView) view.findViewById(R.id.warning)).setText(
- Html.fromHtml(getString(R.string.warning, getVpnLabel()),
- this, null /* tagHandler */));
- mAlertParams.mTitle = getText(R.string.prompt);
- mAlertParams.mPositiveButtonText = getText(android.R.string.ok);
- mAlertParams.mPositiveButtonListener = this;
- mAlertParams.mNegativeButtonText = getText(android.R.string.cancel);
- mAlertParams.mView = view;
- setupAlert();
-
- getWindow().setCloseOnTouchOutside(false);
- getWindow().addPrivateFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
- Button button = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
- button.setFilterTouchesWhenObscured(true);
+ //add by ltj
+ // View view = View.inflate(this, R.layout.confirm, null);
+ // ((TextView) view.findViewById(R.id.warning)).setText(
+ // Html.fromHtml(getString(R.string.warning, getVpnLabel()),
+ // this, null /* tagHandler */));
+ // mAlertParams.mTitle = getText(R.string.prompt);
+ // mAlertParams.mPositiveButtonText = getText(android.R.string.ok);
+ // mAlertParams.mPositiveButtonListener = this;
+ // mAlertParams.mNegativeButtonText = getText(android.R.string.cancel);
+ // mAlertParams.mView = view;
+ // setupAlert();
+
+ // getWindow().setCloseOnTouchOutside(false);
+ // getWindow().addPrivateFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
+ // Button button = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
+ // button.setFilterTouchesWhenObscured(true);
+ // add by ltj end
}
总结
通过查询弹出框字段,通过grep 命令 找到字段id然后定位到弹出框位置,粗暴解决
每日赠言
不抬腿,跨不过栅栏;
不迈步,登不上高山;
空想家,沃土上收获不到五谷;
实干者,沙漠里能挖出清泉。
丢掉幻想扎实干,奋斗前景才灿烂