安卓自动化的一些API

python 复制代码
def run_adb_command():
    pass

创建指定大小的文件

python 复制代码
def create_random_file(file_path: str, file_size: int = 1024):
        # 1M = 1024 * 1024
        if file_path.endswith("/"):
            raise Exception(f"请输入正确的文件路径:{file_path}")
        file_name = file_path.rsplit("/", 1)[1]
        cmd = "dd if=/dev/zero of={} bs={} count=1".format(file_path, file_size)
        result = run_adb_command(func=cmd)
        if file_name in run_adb_command(func=f"ls {file_path}"):
            return True
        raise Exception(f"创建文件失败: {result}")

查看安卓系统时间

python 复制代码
def get_android_time(format: str = "+%Y%m%d%H%M%S"):
        """
            format:
                "+%Y%m%d%H%M%S": 20240612042045
                "+%F": 2024-06-12
                "+%R": 04:20
                "+%s": 1718241156
        """
        return run_adb_command(func=f"date {format}")
相关推荐
JudithHuang几秒前
把本地服务暴露到公网
运维
敲代码的瓦龙31 分钟前
Jetpack?ViewModel!!!
android·开发语言·kotlin·android-studio
yt004yt39 分钟前
### 越华环保集团|绿岛 VOCs 集中治理,管网系统安全设计工程实战分享
大数据·运维
yt004yt1 小时前
越华环保集团|绿岛 VOCs 集中治理,管网系统安全设计工程实战分享
大数据·运维
Godikov1 小时前
Android 工控终端实战:从秒级卡顿到毫秒响应,SQLite/LitePal 性能优化全记录
android
晚安日记wanna1 小时前
压测 TPS 卡在 800CPU 只跑四成六步定位法
运维·面试·测试
吴声子夜歌2 小时前
Shell编程实例——bash入门
linux·运维·shell
爱和冰阔落3 小时前
【Linux】条件变量为什么必须配合互斥锁:从 pthread_cond_wait 到阻塞队列
linux·运维·c++·缓存·中间件·安卓
星间都市山脉3 小时前
Android16 SystemService.onBootPhase 调用时机
android·java·linux·windows·ubuntu
swithun3 小时前
不用 WebView,我用 Kotlin + Compose Multiplatform 重写 Mermaid,并做了 2048 组对拍
android·开源·kotlin