一、简介

由无障碍(一)功能实现我们知道,无障碍服务可以获取界面上的控件和控件的文案信息。那么就可以通过文案做一些自动化操作。

比如:自动刷新,找到列表中符合条件的票务信息、订单信息,找到抢票按钮,实现自动抢单操作。

二、无障碍抓取屏幕数据

以一个简单的listview为例,写一个简单的布局,尝试使用无障碍抓取页面数据。

item布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:padding="15dp"><ImageViewandroid:layout_width="48dp"android:layout_height="48dp"android:src="@mipmap/ic_launcher" /><TextViewandroid:id="@+id/tv_title"android:layout_width="wrap_content"android:layout_height="48dp"android:layout_marginLeft="58dp"android:gravity="center_vertical"android:text="我是一个title" /><TextViewandroid:id="@+id/click_me"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_marginTop="50dp"android:background="#ff0000"android:padding="10dp"android:text="点我"android:textColor="@color/white"android:textSize="16sp"android:textStyle="bold" />
</RelativeLayout>

显示效果:

抓取结果:
下方是抓到的数据,可以看到,每个条目的的title都被抓取到了。

setttleNodeInfo getClassName:android.widget.TextView, getText:Demo
setttleNodeInfo getClassName:android.widget.ListView, getText:null
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:我是title:0
setttleNodeInfo getClassName:android.widget.TextView, getText:点我
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:我是title:1
setttleNodeInfo getClassName:android.widget.TextView, getText:点我
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:我是title:2
setttleNodeInfo getClassName:android.widget.TextView, getText:点我
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:我是title:3
setttleNodeInfo getClassName:android.widget.TextView, getText:点我
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:我是title:4
setttleNodeInfo getClassName:android.widget.TextView, getText:点我
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:我是title:5
setttleNodeInfo getClassName:android.widget.TextView, getText:点我
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:我是title:6
setttleNodeInfo getClassName:android.widget.TextView, getText:点我

三、无障碍检测与防范

上述问题对于一些需要抢单的软件来说,可能会有第三方插件开发,从而导致不公平的抢单操作。

为了避免以上问题,可以有以下的方法:
1、对无障碍功能检测,如果开启无障碍功能,提醒用户运行环境问题。最好不要禁止用户使用app,因为有些无障碍功能并不是真的用来抢单的。
2、针对无障碍app的应用名称、包名进行封禁。
3、对于敏感信息,转换成图片形式进行展示,防止信息被轻易抓取。

1、无障碍功能开启检测
// 判断无障碍功能是否开启
private boolean isAccessibilityOpen() {AccessibilityManager accessibilityManager = (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);return accessibilityManager.isEnabled();
}
// 直接查询已经启用的service
public boolean isAccessibilityOpen2() {AccessibilityManager accessibilityManager = (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);List<AccessibilityServiceInfo> accessibilityservices = accessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_GENERIC);return accessibilityservices != null && !accessibilityservices.isEmpty();
}
2、listView的item中包含title的数据转换成图片展示

item布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:padding="15dp"><ImageViewandroid:id="@+id/img_layout"android:layout_width="wrap_content"android:layout_height="wrap_content" /><TextViewandroid:id="@+id/click_me"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_marginTop="50dp"android:background="#ff0000"android:padding="10dp"android:text="点我"android:textColor="@color/white"android:textSize="16sp"android:textStyle="bold" />
</RelativeLayout>

Adapter代码:

public class MyImgAdapter extends BaseAdapter {private final Context mContext;private RelativeLayout mRealLayout;public MyImgAdapter(Context context) {this.mContext = context;}@Overridepublic int getCount() {return 10;}@Overridepublic Object getItem(int position) {return null;}@Overridepublic long getItemId(int position) {return 0;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {ViewHolder viewHolder;if (convertView == null) {convertView = LayoutInflater.from(mContext).inflate(R.layout.item_test_img, null);viewHolder = new ViewHolder(convertView);convertView.setTag(viewHolder);} else {viewHolder = (ViewHolder) convertView.getTag();}viewHolder.mImgLayout.setImageBitmap(genRealLayout(position));viewHolder.mClickMe.setOnClickListener(v -> Toast.makeText(mContext, "点了我了:" + position, Toast.LENGTH_SHORT).show());return convertView;}// 通过数据获取bitmapprivate synchronized Bitmap genRealLayout(int position) {if (mRealLayout == null) {mRealLayout = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.item_real_layout, null);}((TextView) mRealLayout.findViewById(R.id.tv_title)).setText("我是Img的title:" + position);// 主动测量一次mRealLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);int w = mRealLayout.getMeasuredWidth();int h = mRealLayout.getMeasuredHeight();mRealLayout.layout(0, 0, w, h); // 摆放布局Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);Canvas c = new Canvas(bmp);mRealLayout.draw(c);return bmp;}static class ViewHolder {private TextView mClickMe;private ImageView mImgLayout;public ViewHolder(View view) {mClickMe = view.findViewById(R.id.click_me);mImgLayout = view.findViewById(R.id.img_layout);}}
}

显示效果:

抓取结果:

setttleNodeInfo getClassName:android.widget.TextView, getText:Demo
setttleNodeInfo getClassName:android.widget.ListView, getText:null
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:点我
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:点我
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:点我
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:点我
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:点我
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:点我
setttleNodeInfo getClassName:android.widget.RelativeLayout, getText:null
setttleNodeInfo getClassName:android.widget.TextView, getText:点我

上述方法会产生很多bitmap对象,从而增加内存开销,可以考虑list中的前几个item使用图片形式展示,其他的item继续使用控件方式,从而减少内存开销,并可以影响抓取结果。

无障碍(二)检测与防范相关推荐

  1. 2021年中国云入侵检测与防范市场趋势报告、技术动态创新及2027年市场预测

    云入侵检测与防范市场的企业竞争态势 该报告涉及的主要国际市场参与者有Check Point Software Technologies.Cisco Systems.IBM.Juniper Networ ...

  2. SQL注入漏洞的检测与防范技术

    提 要   本文从SQL注入的基本概念和注入原理入手,分析总结了SQL注入漏洞的检测及其防范技术措施. 关键词  SQL注入漏洞 检测 防范技术 引 言    近几年来随着计算机网络和WEB技术的飞速 ...

  3. android如何避免钓鱼页面,Android应用钓鱼劫持风险的检测与防范

    Android应用钓鱼劫持风险的检测与防范 Detection and Prevention of the Phishing Risk of Android Application DOI: 10.1 ...

  4. Android无障碍检测,Android无障碍服务检测通知

    我试图让我的应用在显示通知时进行检测.我已经在设置应用程序中启用它,并且onServiceConnected确实被调用,但是当我通过Gmail应用程序创建通知或接收电子邮件时,什么也没有发生,onAc ...

  5. 网络安全检测与防范 测试题(二)

    问题 1 Windows操作系统设置账户锁定策略,这可以防止( ).A.木马入侵B.暴力攻击C.IP欺骗D.缓冲区溢出攻击 1 分 问题 2 特洛伊木马攻击的威胁类型属于( ).A.授权侵犯威胁B.植 ...

  6. 利用***检测系统防范******方法介绍

    针对***检测系统的漏洞,让我们来了解一下***的***手法.一旦安装了网络***检测系统,网络***检测系统就会为你分析出网上出现的******事件,而且你能用此***检测系统的反击功能,即时将这种 ...

  7. 信息安全与技术——(十一)恶意代码检测与防范技术

    文章目录 1.恶意代码(Malicious Code) 2.恶意代码对系统带来的影响 3.典型病毒 3.1蠕虫病毒 3.2熊猫烧香病毒 3.3木马病毒 3.4DDoS攻击木马 3.5邮箱病毒 4.恶意 ...

  8. 网络安全检测与防范 练习题(三)

    问题 1 RSA公钥加密系统中,他想给她发送一份邮件,并让她知道是他发出,应选用的加密秘钥是().A.他的公钥B.她的公钥C.他的私钥D.她的私钥 1 分 问题 2 RSA使用不方便的最大问题是(). ...

  9. 网络安全检测与防范 测试题(一)

    问题 1 计算机网络的安全是指( ).A.网络中设备设置环境的安全B.网络使用者的安全C.网络中信息的安全D.网络的财产安全 1 分 问题 2 信息风险主要是指( ).A.信息存储安全B.信息传输安全 ...

最新文章

  1. python爬虫百度百科-如何入门 Python 爬虫?
  2. 2019寒假纪中集训总结学期总结(流水账)
  3. 中国移动 全球通、 动感地带、神州行 的区别
  4. jBPM4.4 window下启动tomcat
  5. 活久见!月薪30k的小程序全栈开发到底有多难?
  6. spring--打印hello--注解component--自动创建对象
  7. 服务器群集:Windows 2000 和 Windows Server 2003 网络配置的最佳做法(转自Technet)
  8. 最长平台(信息学奥赛一本通-T1116)
  9. Spring Boot Redis缓存
  10. 数字的补数——力扣476
  11. android屏幕适配教程,Android屏幕适配方案,android屏幕适配
  12. ASP.NET MVC——Entity Framework连接mysql及问题
  13. Matlab图形修饰之视点处理
  14. mysql多条件顺序_mysql顺序由多个条件
  15. SQL Server 数据操作
  16. 个体户查询_2019年最新修订小规模/一般纳税人?个体户的区别 附最新增值税率表...
  17. mem考试能用计算机吗,Memtest可以通过多少次?
  18. ubuntu独立显卡驱动
  19. 迅速把庸才变将才的七大步
  20. matlab迭代实现矩阵运算,用matlab实现Rayleigh迭代计算矩阵特征值的程序

热门文章

  1. C++异步编程 for VS2011(四)
  2. nfc免root写卡,nfc真正免root的
  3. 2023年MathorCup数模B题赛题
  4. Linux 脚本后台执行
  5. springboot(三):连接mysql数据库
  6. Url被多次转义 URLDecoder.decode(url,“UTF-8“)
  7. 杂散干扰解决办法_6种直流电源杂散干扰的成因分析及解决办法
  8. 怎么合并多个PDF文件?看完这篇你就会了
  9. HTML实现简单注册登录页面
  10. 数字电子技术基础(七):加法器