Improve phh-ota, to be theorically usable without root
This commit is contained in:
parent
617e2320fb
commit
59a5f1a447
@ -204,15 +204,3 @@ cc_binary {
|
|||||||
"oplus-alert-slider.rc",
|
"oplus-alert-slider.rc",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_binary {
|
|
||||||
name: "phh-ota",
|
|
||||||
srcs: [
|
|
||||||
"phh-ota.cpp",
|
|
||||||
],
|
|
||||||
shared_libs: [
|
|
||||||
"libfs_mgr",
|
|
||||||
"libbase",
|
|
||||||
"liblp",
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
12
ota/Android.bp
Normal file
12
ota/Android.bp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
cc_binary {
|
||||||
|
name: "phh-ota",
|
||||||
|
srcs: [
|
||||||
|
"phh-ota.cpp",
|
||||||
|
],
|
||||||
|
shared_libs: [
|
||||||
|
"libfs_mgr",
|
||||||
|
"libbase",
|
||||||
|
"liblp",
|
||||||
|
],
|
||||||
|
init_rc: ["phh-ota.rc"],
|
||||||
|
}
|
@ -2,8 +2,11 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
#include <sys/sysmacros.h>
|
||||||
|
#include <sys/xattr.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <libfiemap/image_manager.h>
|
#include <libfiemap/image_manager.h>
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
|
|
||||||
@ -62,6 +65,22 @@ int main(int argc, char **argv) {
|
|||||||
fprintf(stderr, "Mapping backing image returned %s\n", imgManager->MapImageDevice(imageName, 0ms, &blockDev) ? "true" : "false");
|
fprintf(stderr, "Mapping backing image returned %s\n", imgManager->MapImageDevice(imageName, 0ms, &blockDev) ? "true" : "false");
|
||||||
fprintf(stderr, "blockdev is %s\n", blockDev.c_str());
|
fprintf(stderr, "blockdev is %s\n", blockDev.c_str());
|
||||||
printf("%s\n", blockDev.c_str());
|
printf("%s\n", blockDev.c_str());
|
||||||
|
|
||||||
|
struct stat sb;
|
||||||
|
stat(blockDev.c_str(), &sb);
|
||||||
|
|
||||||
|
if(!S_ISBLK(sb.st_mode)) {
|
||||||
|
fprintf(stderr, "blockDev wasn't block dev\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
unlink("/dev/phh-ota");
|
||||||
|
mknod("/dev/phh-ota", 0644, S_IFBLK | makedev(major(sb.st_rdev), minor(sb.st_rdev)));
|
||||||
|
// Allow system uid to write there
|
||||||
|
chown("/dev/phh-ota", 0, 1000);
|
||||||
|
const char *dstContext = "u:r:phhota_dev:s0";
|
||||||
|
setxattr("/dev/phh-ota", "security.selinux", dstContext, strlen(dstContext), 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(argc>=2 && strcmp(argv[1], "delete-other-slot") == 0) {
|
if(argc>=2 && strcmp(argv[1], "delete-other-slot") == 0) {
|
12
ota/phh-ota.rc
Normal file
12
ota/phh-ota.rc
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
service phh-ota-make /system/bin/phh-ota new-slot
|
||||||
|
seclabel u:r:phhsu_daemon:s0
|
||||||
|
disabled
|
||||||
|
oneshot
|
||||||
|
|
||||||
|
service phh-ota-switch /system/bin/phh-ota switch-slot
|
||||||
|
seclabel u:r:phhsu_daemon:s0
|
||||||
|
disabled
|
||||||
|
oneshot
|
||||||
|
|
||||||
|
on property:sys.boot_completed=1
|
||||||
|
exec u:r:phhsu_daemon:s0 root -- /system/bin/phh-ota delete-other-slot
|
5
sepolicy/phh.te
Normal file
5
sepolicy/phh.te
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
type phhota_dev, dev_type, bdev_type;
|
||||||
|
typeattribute phhota_dev mlstrustedobject;
|
||||||
|
|
||||||
|
allow phhsu_daemon phhota_dev:blk_file rw_file_perms;
|
||||||
|
allow system_app phhota_dev:blk_file rw_file_perms;
|
Loading…
Reference in New Issue
Block a user