android JNI庫實現reboot,recovery,androidjni

來源:互聯網
上載者:User

android JNI庫實現reboot,recovery,androidjni

1、recovery函數:

#defineUPDATE_TITLE"--update_package="#define UPDATE_COMMAND_FILE"/cache/recovery/command"#define UPDATE_FLAG_FILE"/cache/recovery/last_flag"#define LAST_INSTALL_FILE"/cache/recovery/last_install"#define LAST_LOG_FILE"/cache/recovery/last_log"#define LAST_LOCALE_FILE"/cache/recovery/last_locale"#define printf ALOGDint factory_data_reset(void){char data[] = {"--wipe_data\n--locale=en_US\n"};int len = 0, fd;printf("[%s]command:%s\n", __FUNCTION__, data);fd = open(UPDATE_COMMAND_FILE, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);if (fd < 0){printf("[%s]creat command file failed\n", __FUNCTION__);return -3;}len = strlen(data);if (write(fd, data, len) != len){printf("[%s]write command file failed\n", __FUNCTION__);close(fd);return -4;}close(fd);//delete last_install,last_logif (remove(LAST_INSTALL_FILE) != 0)printf("[%s]remove last_install failed\n", __FUNCTION__);if (remove(LAST_LOG_FILE) != 0)printf("[%s]remove last_log failed\n", __FUNCTION__);if (remove(LAST_LOCALE_FILE) != 0)printf("[%s]remove last_locale failed\n", __FUNCTION__);sync();//reboot to recovery__reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "recovery");//這句需要root許可權!printf("[%s]reboot failed\n", __FUNCTION__);return -7;}

2、OTA升級函數

int install_ota_package(char const * package_file, int use_fuse){char *path = NULL;int len = 0, size, fd;len = strlen(package_file);if (len <= 0){printf("[%s]strlen(package_file)=%d\n", __FUNCTION__, len);return -1;}path = (char*)malloc(len+24+3);if (path == 0){printf("[%s]malloc failed\n", __FUNCTION__);return -2;}//UPDATE_COMMAND_FILEmemset(path, 0, len+24+3);if (use_fuse)//(strncmp(package_file, "/vtfuse", 7) != 0){strcpy(path, "--update_package=/vtfuse");strcpy(&path[24], package_file);strcpy(&path[24+len], "\n");}else{strcpy(path, "--update_package=");strcpy(&path[17], package_file);strcpy(&path[17+len], "\n");}printf("[%s]command:%s\n", __FUNCTION__, path);fd = open(UPDATE_COMMAND_FILE, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);if (fd < 0){printf("[%s]creat command file failed\n", __FUNCTION__);free(path);return -3;}size = strlen(path);if (write(fd, path, size) != size){printf("[%s]write command file failed\n", __FUNCTION__);free(path);close(fd);return -4;}close(fd);//UPDATE_FLAG_FILEmemset(path, 0, len+24+3);if (use_fuse)//(strncmp(package_file, "/vtfuse", 7) != 0){strcpy(path, "updating$path=/vtfuse");strcpy(&path[21], package_file);strcpy(&path[21+len], "\n");}else{strcpy(path, "updating$path=");strcpy(&path[14], package_file);strcpy(&path[14+len], "\n");}printf("[%s]last_flag:%s\n", __FUNCTION__, path);fd = open(UPDATE_FLAG_FILE, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);if (fd < 0){printf("[%s]creat last_flag file failed\n", __FUNCTION__);free(path);return -5;}size = strlen(path);if (write(fd, path, size) != size){printf("[%s]write last_flag file failed\n", __FUNCTION__);free(path);close(fd);return -6;}close(fd);//delete last_install,last_logif (remove(LAST_INSTALL_FILE) != 0)printf("[%s]remove last_install failed\n", __FUNCTION__);if (remove(LAST_LOG_FILE) != 0)printf("[%s]remove last_log failed\n", __FUNCTION__);sync();free(path);//reboot to recovery__reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "recovery");//同樣需要root許可權printf("[%s]reboot failed\n", __FUNCTION__);return -7;}


3、其實上面兩個函數如果編譯成exe在root下運行確實可以實現recovery和OTA升級,如何在jni或者apk中掉用和實現了?

3.1 apk申請system許可權,需要簽名或者在源碼中編譯!


3.2 apk是無法直接擷取到root許可權的,最多system許可權,因此我們可以采service!

參考:http://blog.chinaunix.net/uid-12348673-id-3030823.html


3.3 將上面的函數寫兩個應用,編譯後放在/system/bin/下,這樣我們即可在jni中或apk中去開啟service:

init.rc中:

 servicerecovery /system/bin/recovery

 disabled


apk: SystemProperties.set("ctl.start", "recovery");



jni: property_set("ctl.start", "recovery");


3.4這樣就可以實現recovery,OTA了!





幫忙寫一個android JNI調用so庫的android主程式(AndroidActivity)

不明白 你需要什麼
public native int Initialize();//return 成功為1,失敗為0
public native void Uninitialize();// 銷毀
public native void SetFaceDetectParameters(int sensibility);//sensibility 3-低,5-中,7-高
public native int DetectFaces(byte[] picdata);//return 返回檢測結果
public native String test();//測試lib是否串連成功, 直接返回ok
這不就是調用方法了
 
android system recovery <3e> android system recovery utility 問題

你這進入的不是刷機模式,而是Recovery模式。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.