当前位置: 首页 > news >正文

【Android】【root remount】【2】如何判断设备是否remount

前言

高版本的android设备,在remount之后,如果再进行ota升级,会产生异常,从而无法升级成功。

如何判断设备是否remount

当前已android 10 平台为例
当我们执行 adb remount 时,系统调用会调用到system/core/adb/daemon/remount_service.cpp

/** Copyright (C) 2008 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**      http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string>#include "adb.h"
#include "adb_io.h"
#include "adb_unique_fd.h"static constexpr char kRemountCmd[] = "/system/bin/remount";static bool do_remount(int fd, const std::string& cmd) {if (getuid() != 0) {WriteFdExactly(fd, "Not running as root. Try \"adb root\" first.\n");return false;}auto pid = fork();if (pid < 0) {WriteFdFmt(fd, "Failed to fork to %s: %s\n", kRemountCmd, strerror(errno));return false;}if (pid == 0) {// child side of the forkdup2(fd, STDIN_FILENO);dup2(fd, STDOUT_FILENO);dup2(fd, STDERR_FILENO);execl(kRemountCmd, kRemountCmd, cmd.empty() ? nullptr : cmd.c_str(), nullptr);_exit(errno);}int wstatus = 0;auto ret = waitpid(pid, &wstatus, 0);if (ret == -1) {WriteFdFmt(fd, "Failed to wait for %s: %s\n", kRemountCmd, strerror(errno));return false;} else if (ret != pid) {WriteFdFmt(fd, "pid %d and waitpid return %d do not match for %s\n",static_cast<int>(pid), static_cast<int>(ret), kRemountCmd);return false;}if (WIFSIGNALED(wstatus)) {WriteFdFmt(fd, "%s terminated with signal %s\n", kRemountCmd,strsignal(WTERMSIG(wstatus)));return false;}if (!WIFEXITED(wstatus)) {WriteFdFmt(fd, "%s stopped with status 0x%x\n", kRemountCmd, wstatus);return false;}if (WEXITSTATUS(wstatus)) {WriteFdFmt(fd, "%s exited with status %d\n", kRemountCmd, WEXITSTATUS(wstatus));return false;}return true;
}void remount_service(unique_fd fd, const std::string& cmd) {const char* success = do_remount(fd.get(), cmd) ? "succeeded" : "failed";WriteFdFmt(fd.get(), "remount %s\n", success);
}

当前的思路时,再执行do_remount 函数时,添加一个persist变量来判断记录已经remount了,并记录remount次数。
具体修改如下:

#include <unistd.h>
//add 
#include <android-base/properties.h>
//add 
#include <string>
......static bool do_remount(int fd, const std::string& cmd) {......//add std::string prop = android::base::GetProperty("persist.sys.remount.count", "0");int count  = std::stoi(prop) + 1;android::base::SetProperty("persist.sys.remount.count", std::to_string(count));// addreturn true;
}

获取状态remount状态

java

import android.os.SystemProperties;public static final String PROP_REMOUNT_COUNT = "persist.sys.remount.count";/*** NULL* @return device remount status*/public static boolean isRemounted(){return getRemountCount() >0;}/*** NULL* @return get remount count Since first power up*/public static int getRemountCount(){return SystemProperties.getInt(PROP_ROOT_COUNT,0);}

相关文章:

【Android】【root remount】【2】如何判断设备是否remount

前言 高版本的android设备&#xff0c;在remount之后&#xff0c;如果再进行ota升级&#xff0c;会产生异常&#xff0c;从而无法升级成功。 如何判断设备是否remount 当前已android 10 平台为例 当我们执行 adb remount 时&#xff0c;系统调用会调用到system/core/adb/dae…...

html中的“居中”问题详解(超全)

html中的“居中”问题详解&#xff08;超全&#xff09; 图片居中文本居中定位居中元素居中响应式设计中的居中技巧 引言&#xff1a; 在网页设计和开发中&#xff0c;实现元素的居中是一个常见但也常被低估的挑战。无论是在传统的网页布局中还是在响应式设计中&#xff0c;居中…...

【嵌入式学习】ARM day04.11

一、思维导图 二、练习 实现三个灯闪烁 汇编代码 .text .global _start _start: 使能GPIOE和F时钟LDR r0,0x50000A28LDR r1,[R0]ORR R1,R1,#(0X3<<4)STR R1,[R0]配置GPIOE和F的MODER寄存器LDR r0,0x50006000 GPIOELDR R1,0X50007000 G…...

关于部署ELK和EFLKD的相关知识

文章目录 一、ELK日志分析系统1、ELK简介1.2 ElasticSearch1.3 Logstash1.4 Kibana&#xff08;展示数据可视化界面&#xff09;1.5 Filebeat 2、使用ELK的原因3、完整日志系统的基本特征4、ELK的工作原理 二、部署ELK日志分析系统1、服务器配置2、关闭防火墙3、ELK ElasticSea…...

ChatGPT智能写作:开启论文写作新视野

ChatGPT无限次数:点击直达 html ChatGPT智能写作&#xff1a;开启论文写作新视野 引言 在当今信息爆炸的时代&#xff0c;人们需要更有效的工具来帮助他们在各种领域进行写作。ChatGPT作为一项基于人工智能技术的顶尖产品&#xff0c;为论文写作提供了全新的视角和可能性。…...

网络安全---RSA公钥加密与签名

实验项目&#xff1a;RSA公钥加密与签名实验 1.实验目的 本实验的学习目标是让学生获得 RSA 算法的动手经验。 通过课堂学习&#xff0c;学生应该已经了解 RSA 算法的理论部分&#xff0c; 知道在数学上如何生成公钥、私钥以及如何执行加密、解密和签名生成、验证。 通过使用…...

李白打酒加强版 -- 题解 c++

题目链接 : 4408. 李白打酒加强版 - AcWing题库 用户登录 二进制搜索 只能过10%,极限暴力 #include<bits/stdc.h> #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl \n typedef long long LL; const int mod 1e97; const int N 2e510;…...

蓝桥杯——玩具蛇

题目 小蓝有—条玩具蛇&#xff0c;一共有16节&#xff0c;上面标着数字1至16。每—节都是一个正方形的形状。相邻的两节可以成直线或者成90度角。 小蓝还有一个44的方格盒子&#xff0c;用于存放玩具蛇&#xff0c;盒子的方格上依次标着字母A到Р共16个字母。 小蓝可以折叠自…...

百度SSL证书免费申请

百度云也有免费SSL证书可以申请&#xff0c;很多用户找不到&#xff0c;云服务器吧yunfuwuqiba.com整理百度云SSL免费证书申请入口&#xff1a; 1、打开百度云SSL证书购买页面 yunfuwuqiba.com/go/baidu_ssl 点立即购买&#xff0c;如下图&#xff1a; 百度云SSL证书 2、免费…...

SpringBoot Assert断言

文章目录 前言一、Assert说明二、Assert方法三、使用示例四、总结前言 在Spring Boot中,Assert类提供了一系列用于断言的静态方法,用于在代码中进行条件检查和错误处理。这些方法可以帮助我们在开发过程中快速发现和解决问题,提高代码的可靠性和健壮性。 一、Assert说明 在…...

test4121

欢迎关注博主 Mindtechnist 或加入【Linux C/C/Python社区】一起学习和分享Linux、C、C、Python、Matlab&#xff0c;机器人运动控制、多机器人协作&#xff0c;智能优化算法&#xff0c;滤波估计、多传感器信息融合&#xff0c;机器学习&#xff0c;人工智能等相关领域的知识和…...

UI自动化测试重点思考(下)--装饰器/生成器/夹具的使用/描述符的作用/ddt驱动/多线程

UI自动化测试重点思考--装饰器 装饰器装饰器定义装饰器代码示例装饰器的执行如何将装饰器融合到pytest框架里面 生成器创建生成器生成器的定义如何将生成器融合到pytest框架里面 fixture&#xff08;夹具&#xff09;使用pytest fixture 中 scope 参数的详细解释 描述符的总结描…...

C# 字段和属性的区别

区别 在C#中&#xff0c;字段&#xff08;Field&#xff09;和属性&#xff08;Property&#xff09;都是用来封装对象状态的方式&#xff0c;但它们有以下区别&#xff1a; 访问级别&#xff1a; 字段通常是private&#xff0c;而属性可以有不同级别的访问限制&#xff08;…...

备考ICA----Istio实验17---TCP流量授权

备考ICA----Istio实验17—TCP流量授权 1. 环境准备 1.1 环境部署 kubectl apply -f <(istioctl kube-inject -f istio/samples/tcp-echo/tcp-echo.yaml) -n kim kubectl apply -f <(istioctl kube-inject -f istio/samples/sleep/sleep.yaml) -n kim1.2 测试环境 检测…...

[C++][算法基础]树的重心(树图DFS)

给定一颗树&#xff0c;树中包含 n 个结点&#xff08;编号 1∼n&#xff09;和 n−1 条无向边。 请你找到树的重心&#xff0c;并输出将重心删除后&#xff0c;剩余各个连通块中点数的最大值。 重心定义&#xff1a;重心是指树中的一个结点&#xff0c;如果将这个点删除后&a…...

探秘ChatGPT:如何利用AI提升论文写作效率

ChatGPT无限次数:点击直达 html 探秘ChatGPT&#xff1a;如何利用AI提升论文写作效率 在当今信息爆炸的时代&#xff0c;论文写作是许多人工作者每天都要面对的任务。如何更高效地撰写出内容丰富、结构严谨的论文&#xff0c;一直是许多学者和研究人员所追求的目标。随着人…...

多无人机集群协同避障

matlab2020a正常运行 场景1规划结果 场景2规划结果 场景3规划结果 代码地址&#xff1a; 多无人机集群协同避障效果&#xff08;5架&#xff09;资源-CSDN文库...

基于velero和minio实现k8s数据的备份

1.30部署minio rootk8s-harbor:/etc/kubeasz/clusters/k8s-cluster1# docker run \ -d --restartalways -p 9000:9000 -p 9090:9090 –name minio -v /data/minio/data:/data -e “MINIO_ROOT_USERadmin” -e “MINIO_ROOT_PASSWORD12345678” quay.io/minio/minio server…...

【Java核心技术】第4章 对象与类

1 面向对象 2 自定义类 形式&#xff1a; class ClassName { field // 字段 constructor // 构造器&#xff08;构造函数&#xff09; method // 方法 } 如&#xff1a; class Employee {private String name;private double salary;private LocalDate hireDay;public Emp…...

【LeetCode】回溯算法类题目详解

所有题目均来自于LeetCode&#xff0c;刷题代码使用的Python3版本 回溯算法 回溯算法是一种搜索的方法&#xff0c;在二叉树总结当中&#xff0c;经常使用到递归去解决相关的问题&#xff0c;在二叉树的所有路径问题中&#xff0c;我们就使用到了回溯算法来找到所有的路径。 …...

idea大量爆红问题解决

问题描述 在学习和工作中&#xff0c;idea是程序员不可缺少的一个工具&#xff0c;但是突然在有些时候就会出现大量爆红的问题&#xff0c;发现无法跳转&#xff0c;无论是关机重启或者是替换root都无法解决 就是如上所展示的问题&#xff0c;但是程序依然可以启动。 问题解决…...

零门槛NAS搭建:WinNAS如何让普通电脑秒变私有云?

一、核心优势&#xff1a;专为Windows用户设计的极简NAS WinNAS由深圳耘想存储科技开发&#xff0c;是一款收费低廉但功能全面的Windows NAS工具&#xff0c;主打“无学习成本部署” 。与其他NAS软件相比&#xff0c;其优势在于&#xff1a; 无需硬件改造&#xff1a;将任意W…...

【杂谈】-递归进化:人工智能的自我改进与监管挑战

递归进化&#xff1a;人工智能的自我改进与监管挑战 文章目录 递归进化&#xff1a;人工智能的自我改进与监管挑战1、自我改进型人工智能的崛起2、人工智能如何挑战人类监管&#xff1f;3、确保人工智能受控的策略4、人类在人工智能发展中的角色5、平衡自主性与控制力6、总结与…...

中南大学无人机智能体的全面评估!BEDI:用于评估无人机上具身智能体的综合性基准测试

作者&#xff1a;Mingning Guo, Mengwei Wu, Jiarun He, Shaoxian Li, Haifeng Li, Chao Tao单位&#xff1a;中南大学地球科学与信息物理学院论文标题&#xff1a;BEDI: A Comprehensive Benchmark for Evaluating Embodied Agents on UAVs论文链接&#xff1a;https://arxiv.…...

AtCoder 第409​场初级竞赛 A~E题解

A Conflict 【题目链接】 原题链接&#xff1a;A - Conflict 【考点】 枚举 【题目大意】 找到是否有两人都想要的物品。 【解析】 遍历两端字符串&#xff0c;只有在同时为 o 时输出 Yes 并结束程序&#xff0c;否则输出 No。 【难度】 GESP三级 【代码参考】 #i…...

[10-3]软件I2C读写MPU6050 江协科技学习笔记(16个知识点)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16...

Xen Server服务器释放磁盘空间

disk.sh #!/bin/bashcd /run/sr-mount/e54f0646-ae11-0457-b64f-eba4673b824c # 全部虚拟机物理磁盘文件存储 a$(ls -l | awk {print $NF} | cut -d. -f1) # 使用中的虚拟机物理磁盘文件 b$(xe vm-disk-list --multiple | grep uuid | awk {print $NF})printf "%s\n"…...

在Ubuntu24上采用Wine打开SourceInsight

1. 安装wine sudo apt install wine 2. 安装32位库支持,SourceInsight是32位程序 sudo dpkg --add-architecture i386 sudo apt update sudo apt install wine32:i386 3. 验证安装 wine --version 4. 安装必要的字体和库(解决显示问题) sudo apt install fonts-wqy…...

Visual Studio Code 扩展

Visual Studio Code 扩展 change-case 大小写转换EmmyLua for VSCode 调试插件Bookmarks 书签 change-case 大小写转换 https://marketplace.visualstudio.com/items?itemNamewmaurer.change-case 选中单词后&#xff0c;命令 changeCase.commands 可预览转换效果 EmmyLua…...

基于单片机的宠物屋智能系统设计与实现(论文+源码)

本设计基于单片机的宠物屋智能系统核心是实现对宠物生活环境及状态的智能管理。系统以单片机为中枢&#xff0c;连接红外测温传感器&#xff0c;可实时精准捕捉宠物体温变化&#xff0c;以便及时发现健康异常&#xff1b;水位检测传感器时刻监测饮用水余量&#xff0c;防止宠物…...