Loading services/core/java/com/android/server/power/Notifier.java +56 −2 Original line number Diff line number Diff line Loading @@ -94,8 +94,10 @@ public class Notifier { 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_WIRELESS_CHARGING_INTERRUPTED = 4; private static final int MSG_PROFILE_TIMED_OUT = 5; private static final int MSG_WIRED_CHARGING_STARTED = 6; private static final int MSG_WIRED_CHARGING_DISCONNECTED = 7; private static final long[] CHARGING_VIBRATION_TIME = { 40, 40, 40, 40, 40, 40, 40, 40, 40, // ramp-up sampling rate = 40ms Loading @@ -120,6 +122,7 @@ public class Notifier { private final SuspendBlocker mSuspendBlocker; private final WindowManagerPolicy mPolicy; private final ActivityManagerInternal mActivityManagerInternal; private final AudioManager mAudioManager; private final InputManagerInternal mInputManagerInternal; private final InputMethodManagerInternal mInputMethodManagerInternal; @Nullable private final StatusBarManagerInternal mStatusBarManagerInternal; Loading Loading @@ -172,6 +175,7 @@ public class Notifier { mSuspendBlocker = suspendBlocker; mPolicy = policy; mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); mAudioManager = mContext.getSystemService(AudioManager.class); mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); mInputMethodManagerInternal = LocalServices.getService(InputMethodManagerInternal.class); mStatusBarManagerInternal = LocalServices.getService(StatusBarManagerInternal.class); Loading Loading @@ -645,6 +649,21 @@ public class Notifier { mHandler.sendMessage(msg); } /** * Called when wireless charging has been interrupted - to provide user feedback (sound only). */ public void onWirelessChargingInterrupted(@UserIdInt int userId) { if (DEBUG) { Slog.d(TAG, "onWirelessChargingInterrupted"); } mSuspendBlocker.acquire(); Message msg = mHandler.obtainMessage(MSG_WIRELESS_CHARGING_INTERRUPTED); msg.setAsynchronous(true); msg.arg1 = userId; mHandler.sendMessage(msg); } /** * Called when wired charging has started - to provide user feedback */ Loading @@ -660,6 +679,21 @@ public class Notifier { mHandler.sendMessage(msg); } /** * Called when wired charging has been disconnected - to provide user feedback */ public void onWiredChargingDisconnected(@UserIdInt int userId) { if (DEBUG) { Slog.d(TAG, "onWiredChargingDisconnected"); } mSuspendBlocker.acquire(); Message msg = mHandler.obtainMessage(MSG_WIRED_CHARGING_DISCONNECTED); msg.setAsynchronous(true); msg.arg1 = userId; mHandler.sendMessage(msg); } /** * Dumps data for bugreports. * Loading Loading @@ -816,8 +850,15 @@ public class Notifier { final String soundPath = Settings.Global.getString(mContext.getContentResolver(), wireless ? Settings.Global.WIRELESS_CHARGING_STARTED_SOUND : Settings.Global.CHARGING_STARTED_SOUND); final Uri soundUri = Uri.parse("file://" + soundPath); if ("silent".equals(soundPath)) { return; } Uri soundUri = Uri.parse(soundPath); if (soundUri != null) { if (!soundUri.isAbsolute()) { soundUri = Uri.parse("file://" + soundPath); } final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri); if (sfx != null) { sfx.setStreamType(AudioManager.STREAM_SYSTEM); Loading @@ -842,6 +883,11 @@ public class Notifier { mSuspendBlocker.release(); } private void showChargingStopped(@UserIdInt int userId, boolean wireless) { playChargingStartedFeedback(userId, wireless); mSuspendBlocker.release(); } private void lockProfile(@UserIdInt int userId) { mTrustManager.setDeviceLockedForUser(userId, true /*locked*/); } Loading @@ -852,7 +898,9 @@ public class Notifier { final boolean dndOff = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.ZEN_MODE, Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) == Settings.Global.ZEN_MODE_OFF; return enabled && dndOff; final boolean silentMode = mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT; return enabled && dndOff && !silentMode; } private final class NotifierHandler extends Handler { Loading @@ -869,12 +917,18 @@ public class Notifier { case MSG_BROADCAST: sendNextBroadcast(); break; case MSG_WIRELESS_CHARGING_INTERRUPTED: showChargingStopped(msg.arg1, true /* wireless */); break; case MSG_WIRELESS_CHARGING_STARTED: showWirelessChargingStarted(msg.arg1, msg.arg2); break; case MSG_PROFILE_TIMED_OUT: lockProfile(msg.arg1); break; case MSG_WIRED_CHARGING_DISCONNECTED: showChargingStopped(msg.arg1, false /* wireless */); break; case MSG_WIRED_CHARGING_STARTED: showWiredChargingStarted(msg.arg1); break; Loading services/core/java/com/android/server/power/PowerManagerService.java +6 −0 Original line number Diff line number Diff line Loading @@ -2164,6 +2164,12 @@ public final class PowerManagerService extends SystemService if (mIsPowered && !BatteryManager.isPlugWired(oldPlugType) && BatteryManager.isPlugWired(mPlugType)) { mNotifier.onWiredChargingStarted(mUserId); } else if (wasPowered && !mIsPowered) { if (oldPlugType == BatteryManager.BATTERY_PLUGGED_WIRELESS) { mNotifier.onWirelessChargingInterrupted(mUserId); } else { mNotifier.onWiredChargingDisconnected(mUserId); } } else if (dockedOnWirelessCharger) { mNotifier.onWirelessChargingStarted(mBatteryLevel, mUserId); } Loading Loading
services/core/java/com/android/server/power/Notifier.java +56 −2 Original line number Diff line number Diff line Loading @@ -94,8 +94,10 @@ public class Notifier { 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_WIRELESS_CHARGING_INTERRUPTED = 4; private static final int MSG_PROFILE_TIMED_OUT = 5; private static final int MSG_WIRED_CHARGING_STARTED = 6; private static final int MSG_WIRED_CHARGING_DISCONNECTED = 7; private static final long[] CHARGING_VIBRATION_TIME = { 40, 40, 40, 40, 40, 40, 40, 40, 40, // ramp-up sampling rate = 40ms Loading @@ -120,6 +122,7 @@ public class Notifier { private final SuspendBlocker mSuspendBlocker; private final WindowManagerPolicy mPolicy; private final ActivityManagerInternal mActivityManagerInternal; private final AudioManager mAudioManager; private final InputManagerInternal mInputManagerInternal; private final InputMethodManagerInternal mInputMethodManagerInternal; @Nullable private final StatusBarManagerInternal mStatusBarManagerInternal; Loading Loading @@ -172,6 +175,7 @@ public class Notifier { mSuspendBlocker = suspendBlocker; mPolicy = policy; mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); mAudioManager = mContext.getSystemService(AudioManager.class); mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); mInputMethodManagerInternal = LocalServices.getService(InputMethodManagerInternal.class); mStatusBarManagerInternal = LocalServices.getService(StatusBarManagerInternal.class); Loading Loading @@ -645,6 +649,21 @@ public class Notifier { mHandler.sendMessage(msg); } /** * Called when wireless charging has been interrupted - to provide user feedback (sound only). */ public void onWirelessChargingInterrupted(@UserIdInt int userId) { if (DEBUG) { Slog.d(TAG, "onWirelessChargingInterrupted"); } mSuspendBlocker.acquire(); Message msg = mHandler.obtainMessage(MSG_WIRELESS_CHARGING_INTERRUPTED); msg.setAsynchronous(true); msg.arg1 = userId; mHandler.sendMessage(msg); } /** * Called when wired charging has started - to provide user feedback */ Loading @@ -660,6 +679,21 @@ public class Notifier { mHandler.sendMessage(msg); } /** * Called when wired charging has been disconnected - to provide user feedback */ public void onWiredChargingDisconnected(@UserIdInt int userId) { if (DEBUG) { Slog.d(TAG, "onWiredChargingDisconnected"); } mSuspendBlocker.acquire(); Message msg = mHandler.obtainMessage(MSG_WIRED_CHARGING_DISCONNECTED); msg.setAsynchronous(true); msg.arg1 = userId; mHandler.sendMessage(msg); } /** * Dumps data for bugreports. * Loading Loading @@ -816,8 +850,15 @@ public class Notifier { final String soundPath = Settings.Global.getString(mContext.getContentResolver(), wireless ? Settings.Global.WIRELESS_CHARGING_STARTED_SOUND : Settings.Global.CHARGING_STARTED_SOUND); final Uri soundUri = Uri.parse("file://" + soundPath); if ("silent".equals(soundPath)) { return; } Uri soundUri = Uri.parse(soundPath); if (soundUri != null) { if (!soundUri.isAbsolute()) { soundUri = Uri.parse("file://" + soundPath); } final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri); if (sfx != null) { sfx.setStreamType(AudioManager.STREAM_SYSTEM); Loading @@ -842,6 +883,11 @@ public class Notifier { mSuspendBlocker.release(); } private void showChargingStopped(@UserIdInt int userId, boolean wireless) { playChargingStartedFeedback(userId, wireless); mSuspendBlocker.release(); } private void lockProfile(@UserIdInt int userId) { mTrustManager.setDeviceLockedForUser(userId, true /*locked*/); } Loading @@ -852,7 +898,9 @@ public class Notifier { final boolean dndOff = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.ZEN_MODE, Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) == Settings.Global.ZEN_MODE_OFF; return enabled && dndOff; final boolean silentMode = mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT; return enabled && dndOff && !silentMode; } private final class NotifierHandler extends Handler { Loading @@ -869,12 +917,18 @@ public class Notifier { case MSG_BROADCAST: sendNextBroadcast(); break; case MSG_WIRELESS_CHARGING_INTERRUPTED: showChargingStopped(msg.arg1, true /* wireless */); break; case MSG_WIRELESS_CHARGING_STARTED: showWirelessChargingStarted(msg.arg1, msg.arg2); break; case MSG_PROFILE_TIMED_OUT: lockProfile(msg.arg1); break; case MSG_WIRED_CHARGING_DISCONNECTED: showChargingStopped(msg.arg1, false /* wireless */); break; case MSG_WIRED_CHARGING_STARTED: showWiredChargingStarted(msg.arg1); break; Loading
services/core/java/com/android/server/power/PowerManagerService.java +6 −0 Original line number Diff line number Diff line Loading @@ -2164,6 +2164,12 @@ public final class PowerManagerService extends SystemService if (mIsPowered && !BatteryManager.isPlugWired(oldPlugType) && BatteryManager.isPlugWired(mPlugType)) { mNotifier.onWiredChargingStarted(mUserId); } else if (wasPowered && !mIsPowered) { if (oldPlugType == BatteryManager.BATTERY_PLUGGED_WIRELESS) { mNotifier.onWirelessChargingInterrupted(mUserId); } else { mNotifier.onWiredChargingDisconnected(mUserId); } } else if (dockedOnWirelessCharger) { mNotifier.onWirelessChargingStarted(mBatteryLevel, mUserId); } Loading