日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

rk android8.1加密,Android 8.1RK平台增加自定义脚本,修改文件权限

發布時間:2025/3/20 Android 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 rk android8.1加密,Android 8.1RK平台增加自定义脚本,修改文件权限 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近RK3326項目上遇到個問題,OTA升級完重啟后需要去/cache/recovery目錄下讀取一個文件,last_flag,讀取過程中報錯,提示沒有權限,很奇怪,我的明明是系統應用,也加了權限還是報錯,所以寫個腳本在讀取文件之前先設置一下文件的權限,這樣就能讀取到文件里面的內容。

首先建立一個腳本 rp_update_file.sh ,內容很簡單,就是修改下文件權限如下

#!/system/bin/sh

su

chmod 777 /cache/recovery/last_flag

文件放在device/rockchip/rk3326目錄下,然后在init.rk3326.rc中添加一個服務,

#for rp file update

service rp_update_file /system/bin/sh /system/etc/rp_update_file.sh

class main

user root

group root

disabled

oneshot

seclabel u:r:shell:s0

再增加一個變量來控制這個服務

on property:persist.rpfileupdate.enable=1

start rp_update_file

on property:persist.rpfileupdate.enable=0

stop rp_update_file

設置一個property,當persist.rpfileupdate.enable=1 時就會去執行這個腳本。

當然還需要給這個腳本添加權限,在system/core/libcutilsfs_config.cpp 目錄中增加

diff --git a/core/libcutils/fs_config.cpp b/core/libcutils/fs_config.cpp

old mode 100644

new mode 100755

index cc96ff8..9399694

--- a/core/libcutils/fs_config.cpp

+++ b/core/libcutils/fs_config.cpp

@@ -162,6 +162,8 @@ static const struct fs_path_config android_files[] = {

{ 00600, AID_ROOT, AID_ROOT, 0, "vendor/default.prop" },

{ 00444, AID_ROOT, AID_ROOT, 0, ven_conf_dir + 1 },

{ 00444, AID_ROOT, AID_ROOT, 0, ven_conf_file + 1 },

+

+ { 00755, AID_ROOT, AID_ROOT, 0, "system/etc/rp_update_file.sh" },

// the following two files are INTENTIONALLY set-uid, but they

// are NOT included on user builds.

OK這樣腳本就加好了,然后在android代碼中讀取文件之前設置一下property,代碼如下

package com.rp.rpreceiver;

import android.app.AlertDialog;

import android.content.BroadcastReceiver;

import android.content.ComponentName;

import android.content.Context;

import android.content.Intent;

import android.os.Handler;

import android.os.Message;

import android.os.RecoverySystem;

import android.os.storage.StorageManager;

import android.provider.Settings;

import android.util.Log;

import android.view.WindowManager;

import android.widget.Toast;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java.lang.reflect.Field;

import java.lang.reflect.InvocationTargetException;

import java.lang.reflect.Method;

import java.security.GeneralSecurityException;

import java.util.List;

public class UsbReceiver extends BroadcastReceiver {

private static Boolean isBootComplete = false;

private Handler handler=new Handler(){

@Override

public void handleMessage(Message msg) {

super.handleMessage(msg);

}

};

private static File RECOVERY_DIR = new File("/cache/recovery");

private static File UPDATE_FLAG_FILE = new File(RECOVERY_DIR, "last_flag");

private final String SUCCESS="success";

private final String FAILED="fail";

@Override

public void onReceive(Context context, Intent intent) {

String action = intent.getAction();

Log.i("gyx", "UsbReceiver action=" + action);

Log.i("gyx","isBootComplete="+isBootComplete);

if (action.equals("android.intent.action.BOOT_COMPLETED")) {

setProperty("persist.rpfileupdate.enable","1");

try {

Thread.sleep(2000);

} catch (InterruptedException e) {

e.printStackTrace();

}

int start_ota_upgrade = Settings.System.getInt(context.getContentResolver(), "start_ota_upgrade", 0);

Log.i("gyx","start_ota_upgrade="+start_ota_upgrade);

String command = readFlagCommand();

if(start_ota_upgrade==1){

Settings.System.putInt(context.getContentResolver(),"start_ota_upgrade",0);

if(command!=null ){

if (command.startsWith("success")) {

Log.i("gyx","update success");

} else if (command.startsWith("updating")) {

Log.i("gyx","update failed");

}

}else {

Log.i("gyx","command =null update failed");

}

}

setProperty("persist.rpfileupdate.enable","0");

isBootComplete = true;

}else if (action.equals("android.intent.action.MEDIA_MOUNTED") && isBootComplete) {

String sdCardPath = getSdCardPath(context);

String path = FindFileOnUSB("update.zip");

if (path.equals("")) {

Log.i("gyx","update.zip not found");

} else {

Log.i("gyx","update system");

systemUpdate(context, sdCardPath + "/update.zip");

}

}

}

public static void setProperty(String key, String value) {

try {

Class> c = Class.forName("android.os.SystemProperties");

Method set = c.getMethod("set", String.class, String.class);

set.invoke(c, key, value);

} catch (Exception e) {

e.printStackTrace();

}

}

public String getSdCardPath(Context context) {

int TYPE_PUBLIC = 0;

File file = null;

String path = null;

StorageManager mStorageManager = context.getSystemService(StorageManager.class);

Class> mVolumeInfo = null;

try {

mVolumeInfo = Class.forName("android.os.storage.VolumeInfo");

Method getVolumes = mStorageManager.getClass().getMethod(

"getVolumes");

Method volType = mVolumeInfo.getMethod("getType");

Method isMount = mVolumeInfo.getMethod("isMountedReadable");

Method getPath = mVolumeInfo.getMethod("getPath");

Field internalPath = mVolumeInfo.getDeclaredField("internalPath");

List mListVolumeinfo = (List) getVolumes

.invoke(mStorageManager);

Log.d("getSdCardPath", "mListVolumeinfo.size=" + mListVolumeinfo.size());

for (int i = 0; i < mListVolumeinfo.size(); i++) {

int mType = (Integer) volType.invoke(mListVolumeinfo.get(i));

Log.d("getSdCardPath", "mType=" + mType);

if (mType == TYPE_PUBLIC) {

boolean misMount = (Boolean) isMount.invoke(mListVolumeinfo.get(i));

Log.d("getSdCardPath", "misMount=" + misMount);

if (misMount) {

file = (File) getPath.invoke(mListVolumeinfo.get(i));

if (file != null) {

// path = file.getAbsolutePath();

path = (String) internalPath.get(mListVolumeinfo.get(i));

Log.d("getSdCardPath", "path=" + path);

return path;

}

}

}

}

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (NoSuchMethodException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalAccessException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalArgumentException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (InvocationTargetException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (NoSuchFieldException e) {

e.printStackTrace();

}

return "";

}

public void systemUpdate(final Context context, String filepath) {

File updaterFile = new File(filepath);

try {

//升級

RecoverySystem.installPackage(context, updaterFile);

} catch (IOException e) {

e.printStackTrace();

}

}

public static String readFlagCommand() {

if (!UPDATE_FLAG_FILE.exists()) {

return null;

}

Log.d("RKRecoverySystem", "UPDATE_FLAG_FILE is exists");

char[] buf = new char[128];

int readCount = 0;

try {

readCount = new FileReader(UPDATE_FLAG_FILE).read(buf, 0, buf.length);

Log.d("RKRecoverySystem", "readCount = " + readCount + " buf.length = " + buf.length);

} catch (IOException e) {

Log.i("gyx","",e);

Log.e("RKRecoverySystem", "can not read /cache/recovery/last_flag!");

} finally {

UPDATE_FLAG_FILE.delete();

}

StringBuilder sBuilder = new StringBuilder();

int i = 0;

while (i < readCount && buf[i] != '\u0000') {

sBuilder.append(buf[i]);

i++;

}

return sBuilder.toString();

}

}

這樣就大功告成了

總結

以上是生活随笔為你收集整理的rk android8.1加密,Android 8.1RK平台增加自定义脚本,修改文件权限的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。