android6.0第三方app如何打开串口

折腾了一天,用audit2allow工具解析avc错误,把所有的权限都加上了,还是不行,一直有以下提示:

01-06 23:47:28.170  1932  1932 W port_api.sample: type=1400 audit(0.0:59): avc: denied { write } for name="ttyS0" dev="tmpfs" ino=4864 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:serial_device:s0 tclass=chr_file permissive=0

无意中看到网上这篇文章,在device.te加入type serial_device, dev_type, mlstrustedobject;这一行,问题迎刃而解,原文如下,就不标记出处了,因为我是在一个满是成人弹幕广告的网站上搜到的,嘿嘿。

第三方签名APP,在SElinux下,如何获得对一个内核节点的访问权限

 

在android6.0中,出于安全考虑,不允许第三方签名的app被分配mlstrustedsubject:

在external/sepolicy/untrusted_app.te文件中:

# Do not allow untrusted_app to be assignedmlstrustedsubject.
# This would undermine the per-user isolation model being
# enforced via levelFrom=user in seapp_contexts and the mls
# constraints.  As there is no direct way tospecify a neverallow
# on attribute assignment, this relies on the fact that fork
# permission only makes sense within a domain (hence should
# never be granted to any other domain withinmlstrustedsubject)
# and untrusted_app is allowed fork permission to itself.
neverallow untrusted_app mlstrustedsubject:process fork;

所以在使用第三方签名app时,希望第三方签名app某个进程能够对内核节点进行操作,可按如下修改:

1.在device/sprd/scx20/common/sepolicy/file_contexts 文件中添加:
/dev/abc u:object_r:abc_device:s0 
2.在device/sprd/scx20/common/sepolicy/device.te 文件中添加:
type abc_device, dev_type, mlstrustedobject;

3.在device/sprd/scx20/common/sepolicy/untrusted_app.te 文件中添加:
allow untrusted_app adc_device:chr_fileoperate;

operate为赋予的权限。

注:

mlstrustedsubject:这一attribute包含了所有能越过MLS检查的主体domain。

mlstrustedobject:这一attribute包含了所有能越过MLS检查的客体type。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 6.0及以上版本中,需要动态申请权限才能访问存储空间。以下是一个示例代码,用于启动第三方应用并请求存储权限: ```java private static final int REQUEST_CODE_STORAGE_PERMISSION = 1; // 启动第三方应用 private void launchThirdPartyApp() { Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.thirdpartyapp"); if (launchIntent != null) { if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { // 如果已经授权,直接启动第三方应用 startActivity(launchIntent); } else { // 如果没有授权,请求存储权限 requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE_STORAGE_PERMISSION); } } else { // 第三方应用未安装 Toast.makeText(this, "Third party app not installed.", Toast.LENGTH_SHORT).show(); } } // 处理权限请求结果 @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode == REQUEST_CODE_STORAGE_PERMISSION) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // 用户已授权,启动第三方应用 Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.thirdpartyapp"); startActivity(launchIntent); } else { // 用户拒绝授权,无法启动第三方应用 Toast.makeText(this, "Permission denied, cannot launch third party app.", Toast.LENGTH_SHORT).show(); } } } ``` 在上面的代码中,`launchThirdPartyApp()` 方法会尝试启动指定包名的第三方应用。如果当前应用已经被授予存储权限,直接启动第三方应用;否则,请求存储权限,并在 `onRequestPermissionsResult()` 方法中处理用户的授权结果。如果用户授权,再次尝试启动第三方应用;如果用户拒绝授权,提示用户无法启动第三方应用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值