Recovery文件路径

[Android][Recovery] Recovery下找不到sdcard路径

做升级的时候,把更新包拷贝到sd卡中,然后调用接口进行重启升级

wossoneri.github.io
File update_file = new File("/sdcard/update.zip");
try {
Log.d(“WOW”, "install " + update_file.getAbsolutePath());
RecoverySystem.installPackage(getBaseContext(), update_file);
} catch (IOException e) {
e.printStackTrace();
}

之后进入Recovery模式后报错:
Supported API: 3
charge_status 3, charged 0, status 0, capacity 62
Finding update package…
Opening update package…
E:unknow volume for path [/storage/emulated/0/update.zip]
E:failed to map file
Installation aborted.

说是找不到/storage/emulated/0这个路径?
因为上层用Java写路径的时候,获取的是Android的路径,我们知道,adb shell里面是有/sdcard的路径的,这个路径实际上并不是插入的SD卡路径,而是一个内置路径。

内置路径通过 ls -l 可以看到 /sdcard 的映射

lrwxrwxrwx 1 root root 21 1970-01-01 08:00 sdcard -> /storage/self/primary

也就是说下面几个路径是一样的

/sdcard/

/storage/emulated/0

/storage/self/primary
而外置sd卡路径是

/storage/0658-0900

所以,我们代码里写的是/sdcard但是传到Recovery的路径就变成/storage/emulated/0了。
我们的需求是把升级包放到sdcard里面去,所以就需要修改Recovery里的文件路径。
实际要做的就是把获得到的路径里面/storage/emulated/0替换成/sdcard即可:

Recovery里面的sd卡路径就是/sdcard/

if (update_package) {
    // For backwards compatibility on the cache partition only, if
    // we're given an old 'root' path "CACHE:foo", change it to
    // "/cache/foo".
    if (strncmp(update_package, "CACHE:", 6) == 0) {
        int len = strlen(update_package) + 10;
        char* modified_path = (char*)malloc(len);
        if (modified_path) {
            strlcpy(modified_path, "/cache/", len);
            strlcat(modified_path, update_package+6, len);
            printf("(replacing path \"%s\" with \"%s\")\n",
                   update_package, modified_path);
            update_package = modified_path;
        }
        else
            printf("modified_path allocation failed\n");
    } else if(strncmp(update_package, "/storage/emulated/0/", 20) == 0) {
        int len = strlen(update_package) + 20;
        char* modified_path = (char*)malloc(len);
        if (modified_path) {
            strlcpy(modified_path, "/sdcard/", len);
            strlcat(modified_path, update_package+20, len);
            printf("(replacing path \"%s\" with \"%s\")\n",
                   update_package, modified_path);
            update_package = modified_path;
        }
        else
            printf("modified_path allocation failed\n");
    }

Ref https://blog.csdn.net/wed110/article/details/9943915?utm_source=blogxgwz1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值