android 插入充电器提示音流程

BatteryService 收到底层HealthHal callback 通过发送广播来通知监听电量的继承。
PowerManagerService 启动后注册了BatteryReceiver 来监听电量状态变化。

BatteryService.java

// We are doing this after sending the above broadcasts, so anything processing
// them will get the new sequence number at that point.  (See for example how testing
// of JobScheduler's BatteryController works.)
sendBatteryChangedIntentLocked();
if (mLastBatteryLevel != mHealthInfo.batteryLevel || mLastPlugType != mPlugType) {
    sendBatteryLevelChangedIntentLocked();
}

PowerManagerService.java

// Register for broadcasts from other components of the system.
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
mContext.registerReceiver(new BatteryReceiver(), filter, null, mHandler);


// only play charging sounds if boot is completed so charging sounds don't play
// with potential notification sounds
if (mBootCompleted) {
    if (mIsPowered && !BatteryManager.isPlugWired(oldPlugType)
            && BatteryManager.isPlugWired(mPlugType)) {
        mNotifier.onWiredChargingStarted();
    } else if (dockedOnWirelessCharger) {
        mNotifier.onWirelessChargingStarted(mBatteryLevel);
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章