使用adb工具自动写入脏数据到手机sd卡

文章描述了一种使用Python编写的脚本,通过ADB工具自动对数百台手机进行刷机并写入数据,以确保数据安全。脚本实现了批量处理,提高了工作效率,应对公司数据保护需求。
摘要由CSDN通过智能技术生成

公司有几百台手机需要卖掉,但是又担心手机里面的数据被其他人恢复出来,需要我们重置手机或者刷机一次,然后在写入一边脏数据,把原先的数据覆盖掉,写满sd卡,然后在重新刷一次手机。这样防止数据泄露,更好的保护公司的数据信息。

但是公司给的时间又比较少,公司部门人员有限。还有其他工作,所以最后写了以下脚本,自动写入数据到手机。大大提高了工作效率。

1.首先需要你的电脑下载adb工具包,这个是 Android 平台进行交互的工具

import os
import threading
from tkinter import scrolledtext
from subprocess import run
import ttkbootstrap as ttk
import time

root = ttk.Window(themename="superhero")
root.title('运维工具箱-管理员')
root.geometry('560x400')
# 写入数据路径 脏数据
path4 = r'rhel-8.2-x86_64-boot.iso.7z'


def writeDate_Thread(id_phone):
    ts.insert('end', "执行进程" + str(id_phone) + '\n')
    t1 = time.time()
    i = 0
    a = True
    while a:
        now_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
        now_time1 = time.strftime('%Y%m%d%H%M%S', time.localtime())
        i += 1
        ts.insert('end', now_time + "开始写入" + str(id_phone) + "。。。。。。" + '\n')
        return_status = run(r'E:\pythonProject\platform-tools\adb.exe -s ' + str(
            id_phone) + ' push ' + path4 + ' /sdcard/hn-' + now_time1, shell=True)

        print("刷机返回:" + str(return_status))
        ts.insert('end', "写入数据成功,状态码(0):" + str(return_status.returncode) + '\n')
        if return_status.returncode == 1:
            a = False

    t2 = time.time()
    print("用时:" + str(t2 - t1))
    ts.insert('end', str(id_phone) + "数据写入用时:" + str((t2 - t1) / 60) + "m" + '\n')


def start_write():
    # 读取设备id信息
    deviceId = os.popen(r'platform-tools\adb.exe devices')
    # 提取设备id保存在deviceId_list[]
    low_list = []
    for i in deviceId:
        low_list.append(i)

    deviceId_list = []
    new_list = low_list[1:-1]
    for i in new_list:
        phoneId = i.split('\t')[0]
        deviceId_list.append(phoneId)
    t1 = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
    ts.insert('end', "当前时间" + t1 + "\n")
    if len(deviceId_list) == 0:
        ts.insert('end', "读取设备id失败" + '\n')
    else:
        for id_Phone in deviceId_list:
            ts.insert('end', "开启设备" + str(id_Phone) + "数据写入线程" + '\n')
            t = threading.Thread(target=writeDate_Thread, args=(id_Phone,))
            t.start()


ttk.Button(root, bootstyle="info", command=start_write, text='写入数据').grid(row=2, column=1, pady=120, ipadx=5, )
ttk.Button(root, bootstyle="info", command=root.destroy, text='退出').grid(row=2, column=2, pady=120, )
frame3 = ttk.Labelframe(root, bootstyle="info", text='程序执行信息')
ts = scrolledtext.ScrolledText(frame3, width=36, height=11)
ts.pack()
frame3.grid(row=0, column=1)
root.mainloop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值