android 系統關機,重啟

來源:互聯網
上載者:User

android 系統關機,重啟 
1.android系統的關機,重啟代碼位於frameworks/base/core/jni/android_os_Power.cpp,裡面有

static void android_os_Power_shutdown(JNIEnv *env, jobject clazz)
{/*關機*/
    sync();
#ifdef HAVE_ANDROID_OS
    reboot(RB_POWER_OFF);
#endif
}

static void android_os_Power_reboot(JNIEnv *env, jobject clazz, jstring reason)
{/*重啟*/
    sync();
#ifdef HAVE_ANDROID_OS
    if (reason == NULL) {
        reboot(RB_AUTOBOOT);
    } else {
        const char *chars = env->GetStringUTFChars(reason, NULL);
        __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
                 LINUX_REBOOT_CMD_RESTART2, (char*) chars);
        env->ReleaseStringUTFChars(reason, chars);  // In case it fails.
    }
    jniThrowIOException(env, errno);
#endif
}

2.最終會調用到linux中的sys_reboot,所以我們還是可以做到在android中加入重啟功能的;

關機和重啟在Linux Kernel中的哪些函數裡實現。
reboot的最終實現在arch_reset()函數,它通常定義在arch/arm/mach-xxx/include/mach/system.h裡。system.h被ARM kernel的public code應用,因此你需要定義這個標頭檔,並實現它。
arch_reset的函數原型為
void arch_reset(char mode) 
void arch_reset(char mode) 
關機需要將pm_power_off這個函數指標指向你自己的實現函數。函數指標是這樣定義的
void (*pm_power_off)(void);  ......

 

本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/a3015440/archive/2010/05/29/5633381.aspx

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.