我创建了一个服务并添加到SystemService中。 但我发现我的服务无法选择extsd卡,因为它是WRITE_EXTERNAL_STORAGE的许可。 我读过这个文件: http://www.chainfire.eu/articles/113/Is_Google_blocking_apps_writing_to_SD_cards_/ 并且知道如何在我的系统中添加WRITE_EXTERNAL_STORAGE权限。 但这不是work.emphasized text
我在应用程序中编写测试代码,没关系,我检查权限是否正确如下:
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):写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(系统)gid = 1000(系统)组= 1001(无线电),1002(蓝牙),1003(图形),1004(输入),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 root system 1970-01-02 03:17 asec d --- rwxr-x system sdcard_rw 1970-01-01 00:00 extsd drwxr-xr-x root
system 1970-01-02 03:17 obb drwx ------ root root
1970-01-02 03:17安全drwxrwxr-x系统图形
1970-01-02 03:17 shm d --------- system system 1970-01-02 03:17 udisk
mount
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 none / dev / cpuctl cgroup rw,relatime,cpu 0 0 / dev / block / mmcblk0p5 / system \ text4 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,短名称=混合,UTF8,误差=重新装入-RO 0 0
如何在系统中添加1015组?