Android KK開機按power鍵不能滅屏,須過會兒才能滅屏

來源:互聯網
上載者:User

標籤:android   style   blog   io   color   ar   java   sp   for   

這是Google issue,原生Android4.4都有此問題。流程是:AMS發出BOOT_COMPLETED,PowerManager收到BOOT_COMPLETED後check Boot animation是否完成,如果完成,就會將內部的成員mBootCompleted置為true,之後再按power鍵才會正常休眠。 

PowerManagerService.java在systemReady()方法中動態註冊BootCompletedReceiver監聽ACTION_BOOT_COMPLETED

1             filter = new IntentFilter();2             filter.addAction(Intent.ACTION_BOOT_COMPLETED);3             mContext.registerReceiver(new BootCompletedReceiver(), filter, null, mHandler);
 1     private final class BootCompletedReceiver extends BroadcastReceiver { 2         @Override 3         public void onReceive(Context context, Intent intent) { 4             if (DEBUG_SPEW) { 5                 Slog.d(TAG, "BootCompletedReceiver."); 6             } 7             // This is our early signal that the system thinks it has finished booting. 8             // However, the boot animation may still be running for a few more seconds 9             // since it is ultimately in charge of when it terminates.10             // Defer transitioning into the boot completed state until the animation exits.11             // We do this so that the screen does not start to dim prematurely before12             // the user has actually had a chance to interact with the device.13             startWatchingForBootAnimationFinished();14         }15     }

startWatchingForBootAnimationFinished()發送廣播MSG_CHECK_IF_BOOT_ANIMATION_FINISHED檢查是否開機動畫完成,

1         @Override2         public void handleMessage(Message msg) {3             switch (msg.what) {4                 ……5                 case MSG_CHECK_IF_BOOT_ANIMATION_FINISHED:6                     checkIfBootAnimationFinished();7                     break;8             }9         }
 1     private void checkIfBootAnimationFinished() { 2         if (DEBUG) { 3             Slog.d(TAG, "Check if boot animation finished..."); 4         } 5         // 檢查是否還在跑 bootanim 6         if (SystemService.isRunning(BOOT_ANIMATION_SERVICE)) { 7             mHandler.sendEmptyMessageDelayed(MSG_CHECK_IF_BOOT_ANIMATION_FINISHED, 8                     BOOT_ANIMATION_POLL_INTERVAL); 9             return;10         }11 12         synchronized (mLock) {13             if (!mBootCompleted) {14                 Slog.i(TAG, "Boot animation finished.");15                 handleBootCompletedLocked();16             }17         }18     }

這裡用到SystemService.isRunning(BOOT_ANIMATION_SERVICE)判斷系統開機動畫是否還在運行,若isRunning繼續Check,否則,動畫完成handleBootCompletedLocked();

 1     private void handleBootCompletedLocked() { 2         final long now = SystemClock.uptimeMillis(); 3         mBootCompleted = true; 4         mDirty |= DIRTY_BOOT_COMPLETED; 5         userActivityNoUpdateLocked( 6                 now, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID); 7         if ( mWakefulness == WAKEFULNESS_AWAKE ) { 8             mNotifier.onWakeUpStarted(); 9         }10         updatePowerStateLocked();11     }

到這裡mBootCompleted系統才正在起來,通知更新State。

 

至此,還是只找到原因,沒有好的處理方法,希望高手指點,科普,交流。

目前,比較拙劣的方法是將mBootCompleted=True,設為TRUE。這個改法是讓powermanager不去check boot_completed,這樣可能會產生影響:剛剛開機就按power鍵滅屏後,再次按power鍵是否能正常resume回來。主要是考慮到AMS此時可能還在發BOOT_COMPLETED,而按power鍵滅屏和亮屏的流程會需要AMS發SCREEN_OFF、SCREEN_ON的intent,擔心ActivityManagerService在BOOT_COMPLETED還沒發完的情況下又要響應去發SCREEN_OFF和SCREEN_ON。

 

Android KK開機按power鍵不能滅屏,須過會兒才能滅屏

聯繫我們

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