android p 充拔电提示音

PowerManagerService.java

在这里插入代码片
private void updateIsPoweredLocked(int dirty) {
    if ((dirty & DIRTY_BATTERY_STATE) != 0) {
        final boolean wasPowered = mIsPowered;
        final int oldPlugType = mPlugType;
        final boolean oldLevelLow = mBatteryLevelLow;
        mIsPowered = mBatteryManagerInternal.isPowered(BatteryManager.BATTERY_PLUGGED_ANY);
        mPlugType = mBatteryManagerInternal.getPlugType();
        mBatteryLevel = mBatteryManagerInternal.getBatteryLevel();
        mBatteryLevelLow = mBatteryManagerInternal.getBatteryLevelLow();

        if (DEBUG_SPEW) {
            Slog.d(TAG, "updateIsPoweredLocked: wasPowered=" + wasPowered
                    + ", mIsPowered=" + mIsPowered
                    + ", oldPlugType=" + oldPlugType
                    + ", mPlugType=" + mPlugType
                    + ", mBatteryLevel=" + mBatteryLevel);
        }

        if (wasPowered != mIsPowered || oldPlugType != mPlugType) {
            mDirty |= DIRTY_IS_POWERED;

            // Update wireless dock detection state.
            final boolean dockedOnWirelessCharger = mWirelessChargerDetector.update(
                    mIsPowered, mPlugType);

            // Treat plugging and unplugging the devices as a user activity.
            // Users find it disconcerting when they plug or unplug the device
            // and it shuts off right away.
            // Some devices also wake the device when plugged or unplugged because
            // they don't have a charging LED.
            final long now = SystemClock.uptimeMillis();
            if (shouldWakeUpWhenPluggedOrUnpluggedLocked(wasPowered, oldPlugType,
                    dockedOnWirelessCharger)) {
                wakeUpNoUpdateLocked(now, "android.server.power:POWER", Process.SYSTEM_UID,
                        mContext.getOpPackageName(), Process.SYSTEM_UID);
            }
            userActivityNoUpdateLocked(
                    now, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);

            // 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);
                }
				/*SUN:jicong.wang add for charge out ringtone start {@*/
                if (oldPlugType!=0 && mPlugType ==0 ){
                    Log.d(TAG,"wangjicong onChargeOff");
                    mNotifier.onChargeOff();
                }
				/*SUN:jicong.wang add for charge out ringtone end @}*/
            }
        }

        mBatterySaverStateMachine.setBatteryStatus(mIsPowered, mBatteryLevel, mBatteryLevelLow);
    }
}

Notifier.java

     * SUN:jicong.wang add for charge out ringtone
     */
    public void onChargeOff(){
        if (DEBUG) {
            Slog.d(TAG, "onChargeOff");
        }
        mSuspendBlocker.acquire();
        Message msg = mHandler.obtainMessage(MSG_CHARGE_OFF);
        msg.setAsynchronous(true);
        mHandler.sendMessage(msg);
    }
    /**
     * Called when wired charging has started so as to provide user feedback
     */
    public void onWiredChargingStarted() {
        if (DEBUG) {
            Slog.d(TAG, "onWiredChargingStarted");
        }

        mSuspendBlocker.acquire();
        Message msg = mHandler.obtainMessage(MSG_WIRED_CHARGING_STARTED);
        msg.setAsynchronous(true);
        mHandler.sendMessage(msg);
    }
    private final class NotifierHandler extends Handler {

        public NotifierHandler(Looper looper) {
            super(looper, null, true /*async*/);
        }
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_USER_ACTIVITY:
                    sendUserActivity();
                    break;
                case MSG_BROADCAST:
                    sendNextBroadcast();
                    break;
                case MSG_WIRELESS_CHARGING_STARTED:
                    showWirelessChargingStarted(msg.arg1);
                    break;
                case MSG_SCREEN_BRIGHTNESS_BOOST_CHANGED:
                    sendBrightnessBoostChangedBroadcast();
                    break;
                case MSG_PROFILE_TIMED_OUT:
                    lockProfile(msg.arg1);
                    break;
                case MSG_WIRED_CHARGING_STARTED:
                    showWiredChargingStarted();
                    break;
				/*SUN:jicong.wang add for charge out ringtone start {@*/	
                case MSG_CHARGE_OFF:
                    playChargingStartedSound();
                    mSuspendBlocker.release();
                    break;
				/*SUN:jicong.wang add for charge out ringtone end @}*/	
            }
        }
    }
    private static final String TAG = "PowerManagerNotifier";

    private static final boolean DEBUG = false;

    private static final int INTERACTIVE_STATE_UNKNOWN = 0;
    private static final int INTERACTIVE_STATE_AWAKE = 1;
    private static final int INTERACTIVE_STATE_ASLEEP = 2;

    private static final int MSG_USER_ACTIVITY = 1;
    private static final int MSG_BROADCAST = 2;
    private static final int MSG_WIRELESS_CHARGING_STARTED = 3;
    private static final int MSG_SCREEN_BRIGHTNESS_BOOST_CHANGED = 4;
    private static final int MSG_PROFILE_TIMED_OUT = 5;
    private static final int MSG_WIRED_CHARGING_STARTED = 6;
    private static final int MSG_CHARGE_OFF = 7;//SUN:jicong.wang add for charg out ringtone

你可能感兴趣的:(Android)