1

我创建了一个服务并添加到 SystemService 中。但我发现我的服务不能选择 extsd 卡,因为它是 WRITE_EXTERNAL_STORAGE 的许可。我已经阅读了文件: http: //www.chainfire.eu/articles/113/Is_Google_blocking_apps_writing_to_SD_cards_/ 并且知道如何在我的系统中添加 WRITE_EXTERNAL_STORAGE 权限。但它不起作用。强调文本

我在app中写了测试代码,没问题,我检查权限是否正确,如下所示:

File newDir = new File("/mnt/extsd/");
newDir.mkdirs();
File wtSd = new File(newDir.getAbsolutePath(), "file.txt");
BufferedWriter writer;

try {
    java.lang.Process process = Runtime.getRuntime().exec("id");
    InputStream input = process.getInputStream();
    byte[] bytes = new byte[1204];
    int len;
    while((len = (input.read(bytes))) > 0){
        System.out.print(new String(bytes, 0, len));
    }
    input.close();
} catch(IOException e) {
    e.printStackTrace();
}

Log.i(TAG, "write extsd"+wtSd.getAbsolutePath()+wtSd.getName());
try {
    writer = new BufferedWriter(new FileWriter(wtSd));
    writer.write("hello, extsd");
    writer.flush();
    writer.close();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

权限是: I/System.out(2804): uid=10036(app_36) gid=10036(app_36) groups=1000(system),1015(sdcard_rw) I/AR300 UPD(2804): write extsd/mnt/extsd /file.txtfile.txt


但在系统服务中的相同代码,这很糟糕

代码是

try{
    java.lang.Process process = Runtime.getRuntime().exec("id");
    InputStream input = process.getInputStream();
    byte[] bytes = new byte[1204];
    int len;
    while((len = (input.read(bytes))) > 0) {
        System.out.print(new String(bytes, 0, len));
    }
    input.close();
} catch(IOException e) {
    e.printStackTrace();
}

File newDir = new File("/mnt/extsd/");
newDir.mkdirs();
File wtSd = new File(newDir.getAbsolutePath(), "file.txt");
BufferedWriter writer;

Log.i(TAGC, "write extsd"+wtSd.getAbsolutePath());
try {
    writer = new BufferedWriter(new FileWriter(wtSd));
    writer.write("hello, extsd");
    writer.flush();
    writer.close();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

我的服务权限是:I/System.out(2249): uid=1000(system) gid=1000(system) groups=1001(radio),1002(bluetooth),1003(graphics),1004(input),1005(音频),1006(相机),1007(日志),1008(指南针),1009(安装),1010(wifi),1018(usb),3001(net_bt_admin),3002(net_bt),3003(inet),3006( net_bw_stats),3007(net_bw_acct)

很清楚,我的服务不能选择 1015(sdcard_rw)


drwxr-xr-x 根系统 1970-01-02 03:17 asc d---rwxr-x 系统 sdcard_rw 1970-01-01 00:00 extsd drwxr-xr-x 根
系统 1970-01-02 03:17 obb drwx------ root root
1970-01-02 03:17 安全 drwxrwxr-x 系统图形
1970-01-02 03:17 shm d--------- 系统系统 1970-01-02 03 :17 u盘


root@android:/mnt # mount rootfs / rootfs ro,relatime 0 0 tmpfs /dev tmpfs rw,nosuid,relatime,mode=755 0 0 devpts /dev/pts devpts rw,relatime,mode=600 0 0 proc /proc proc rw,relatime 0 0 sysfs /sys sysfs rw,relatime 0 0 none /acct cgroup rw,relatime,cpuacct 0 0 tmpfs /mnt/asec tmpfs rw,relatime,mode=755,gid=1000 0 0 tmpfs /mnt/obb tmpfs rw,relatime,mode=755,gid=1000 0 0 tmpfs /mnt/shm tmpfs rw,relatime,size=1024k,mode=775,uid=1000,gid=1003 0 0 无 /dev/cpuctl cgroup rw,relatime, cpu 0 0 /dev/block/mmcblk0p5 /system ext4 ro,relatime,user_xattr,barrier=1,data=ordered 0 0 /dev/block/mmcblk0p7 /data ext4 rw,nosuid,nodev,noatime,nodiratime,errors=panic, user_xattr,barrier=0,nomblk_io_submit,data=ordered,noauto_da_alloc,discard 0 0 /dev/block/mmcblk0p6 /cache ext4 rw,nosuid,nodev,relatime,user_xattr,barrier=1,data=ordered 0 0 /dev/block/mmcblk0p8 /vendor ext4 rw,nosuid,nodev,relatime,user_xattr,barrier=1,data=ordered 0 0 none /sys/kernel/debug debugfs rw,relatime 0 0 /dev/block/vold/179:25 /mnt/extsd vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437 ,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0


如何在系统中添加1015组??

4

0 回答 0