1 原理
在弹窗的位置上修改代码 或者是直接授权,不让弹窗弹出来。
2 解决方案(Android O)
@1 不显示蓝牙的错误提示信息Toast
修改文件:asop/frameworks/base/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java修改内容为:
private void showUnbondMessage(Context context, String name, int reason) {
int errorMsg;
switch (reason) {
case BluetoothDevice.UNBOND_REASON_AUTH_FAILED:
errorMsg = R.string.bluetooth_pairing_pin_error_message;
break;
case BluetoothDevice.UNBOND_REASON_AUTH_REJECTED:
errorMsg = R.string.bluetooth_pairing_rejected_error_message;
break;
case BluetoothDevice.UNBOND_REASON_REMOTE_DEVICE_DOWN:
errorMsg = R.string.bluetooth_pairing_device_down_error_message;
break;
case BluetoothDevice.UNBOND_REASON_DISCOVERY_IN_PROGRESS:
case BluetoothDevice.UNBOND_REASON_AUTH_TIMEOUT:
case BluetoothDevice.UNBOND_REASON_REPEATED_ATTEMPTS:
case BluetoothDevice.UNBOND_REASON_REMOTE_AUTH_CANCELED:
errorMsg = R.string.bluetooth_pairing_error_message;
break;
default:
Log.w(TAG,"showUnbondMessage: Not displaying any message for reason: " + reason);
return;
}
//将这句话注释掉即可不再显示Toast
//BluetoothUtils.showError(context, name, errorMsg);
}
@2 系统级APP(针对system priv-app && system app)不弹权限弹窗 解决方案
在文件frameworks/base/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java中做如下修改:
@@ -739,6 +739,12 @@ final class DefaultPermissionGrantPolicy {
STORAGE_PERMISSIONS, true, userId);
}
+ //XXX Launcher
+ PackageParser.Package XXXPckg = getPackageLPr("com.XXX.launcher");
+ if(XXXPckg !=null){
+ grantRuntimePermissionsLPw(XXXPckg,STORAGE_PERMISSIONS,userId);
+ grantRuntimePermissionsLPw(XXXPckg,LOCATION_PERMISSIONS,userId);
+ //...
+ }
mService.mSettings.onDefaultRuntimePermissionsGrantedLPr(userId);
}
}
@3 普通APP 不弹权限弹窗 解决方案
在文件 frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java 中做如下修改:
@@ -1680,8 +1680,9 @@ public class PackageManagerService extends IPackageManager.Stub
InstallArgs args = data.args;
PackageInstalledInfo parentRes = data.res;
- final boolean grantPermissions = (args.installFlags
- & PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS) != 0;
+ /*final boolean grantPermissions = (args.installFlags
+ & PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS) != 0;*/
+ final boolean grantPermissions = true;
final boolean killApp = (args.installFlags
& PackageManager.INSTALL_DONT_KILL_APP) == 0;
final boolean virtualPreload = ((args.installFlags
@4 USB权限 对话框 不弹窗 解决方案
在文件 frameworks/base/packages/SystemUI/src/com/android/systemui/usb/UsbPermissionActivity.java 中做如下修改:
@@ -110,8 +110,9 @@ public class UsbPermissionActivity extends AlertActivity
com.android.internal.R.id.clearDefaultHint);
mClearDefaultHint.setVisibility(View.GONE);
- setupAlert();
-
+ //setupAlert();
+ mPermissionGranted = true;
+ finish();
}
@Override
@5 ANR/Crash 对话框 不弹窗 解决方案
在文件 frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java 中做如下修改:
@@ -626,7 +626,9 @@ public class ActivityManagerService extends IActivityManager.Stub
// Whether we should show our dialogs (ANR, crash, etc) or just perform their
// default action automatically. Important for devices without direct input
// devices.
- private boolean mShowDialogs = true;
+ //private boolean mShowDialogs = true;
+ private boolean mShowDialogs = false;
+
private final VrController mVrController;