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

android高版本适配使用Tools.java

随着android版本的提升,原生Tools不公开并且不能被正常使用,为了延续项目的功能,修改如下:

/** Copyright (C) 2006 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.*/package android.os;import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.util.Log;import java.io.DataOutputStream;/*** {@hide}*/
@SystemApi
public class Tools {private static final String TAG = "Tools_agenew";/*** @hide*/@SystemApipublic static int system(@NonNull String cmd) {return executeCommand(cmd);}@UnsupportedAppUsageprivate Tools() {}/*** @hide*/@SystemApipublic synchronized static int executeCommand(String command) {int status = -1;java.lang.Process process = null;DataOutputStream os = null;Log.d(TAG, "exec_start:" + command);try {process = Runtime.getRuntime().exec(command);status = process.waitFor();if (status == 0) {Log.i(TAG, "exec succeed.");} else {Log.i(TAG, "exec failed.");}} catch (Exception e) {Log.e(TAG, e.toString());e.printStackTrace();} finally {try {if (os != null) {os.close();}if (process != null) {process.destroy();}} catch (Exception e) {Log.e(TAG, e.toString());e.printStackTrace();}}Log.d(TAG, "exec_end:" + command);return status;}}

vendor/sprd/platform/frameworks/base/ex-interface/core/java/android/provider/UnisocSettings.java

+        /**
+         * add for com.sprd.runtime test
+         * putInt 1 means start testing, 0 for the end.
+         * @hide
+         */
+       @UnisocHiddenApi
+        public static final String UNISOC_RUNTIME_USER_ACTION = "com.sprd.runtime.USER_ACTION";

注意:请更新对应平台的api和sepolicy,笔者使用展锐T606 android 13平台,对应修改如下
system-current.txt

+  public class Tools {
+    method public static int executeCommand(String);
+    method public static int system(@NonNull String);
+  }

system-lint-baseline.txt

+VisiblySynchronized: android.os.Tools#executeCommand(String):
+   Internal locks must not be exposed: method android.os.Tools.executeCommand(String)

unisoc-hidden-current.txt

+  public class Tools {
+   method public static int executeCommand(String);
+    method public static void system(@NonNull String);
+  }

device/sprd/mpool/sepolicy/vendor/untrusted_app.te

+allow untrusted_app property_socket:sock_file { write };
+allow untrusted_app init:unix_stream_socket { connectto };
+allow untrusted_app default_prop:property_service { set };

system/sepolicy/private/app_neverallows.te

# Do not allow untrusted apps to connect to the property service
# or set properties. b/10243159
#neverallow { all_untrusted_apps -mediaprovider } property_socket:sock_file write;
#neverallow { all_untrusted_apps -mediaprovider } init:unix_stream_socket connectto;
#neverallow { all_untrusted_apps -mediaprovider } property_type:property_service set;

system/sepolicy/private/property.te

neverallow {domain-init
+  -untrusted_app
} default_prop:property_service set;
http://www.lryc.cn/news/254426.html

相关文章:

  • 面试官:说说webpack中常见的Loader?解决了什么问题?
  • 【蓝桥杯省赛真题50】Scratch智能计价器 蓝桥杯scratch图形化编程 中小学生蓝桥杯省赛真题讲解
  • 折半查找(数据结构实训)
  • AR助推制造业智能转型:实时远程协作与可视化引领生产创新
  • 【用unity实现100个游戏之18】从零开始制作一个类CSGO/CS2、CF第一人称FPS射击游戏——基础篇3(附项目源码)
  • sed 流式编辑器
  • Linux shell编程学习笔记33:type 命令
  • 【数据结构】—红黑树(C++实现)
  • 内衣洗衣机和手洗哪个干净?高性价比内衣洗衣机推荐
  • TikTok与互动广告:品牌如何打破传统界限
  • 跟着Nature Communications学习Hisat-Trinity-PASA等分析流程
  • Unity中Batching优化的动态合批
  • 2022年第十一届数学建模国际赛小美赛B题序列的遗传过程解题全过程文档及程序
  • 【Linux】静态库与动态库制作及运行原理
  • 工具站推荐
  • 【JS】toFixed()无法精准保留小数的解决方案
  • vue3版本学习
  • 【WPF.NET开发】创建简单WPF应用
  • 视频智能分析国标GB28181云平台EasyCVR加密机授权异常是什么原因?
  • Mysql安全之基础合规配置
  • 前后端分离项目跨域请求
  • OpenEuler系统桌面终端设置字体
  • repo常用命令解析(持续更新)
  • 关于小红书商单变现的一些答疑
  • 使用 Kubernetes Agent Server 实现 GitOps
  • Day12 qt QMianWindow,资源文件,对话框,布局方式,常用ui控件
  • Python实现广义线性回归模型(statsmodels GLM算法)项目实战
  • GNSEC 2022年第8届全球下一代软件工程线上峰会-核心PPT资料下载
  • nVisual能为数据中心解决什么问题?
  • Android--Jetpack--Databinding详解