Merge "Play different sounds for wired/wireless charging"
This commit is contained in:
@@ -8594,12 +8594,18 @@ public final class Settings {
|
||||
public static final String POWER_SOUNDS_ENABLED = "power_sounds_enabled";
|
||||
|
||||
/**
|
||||
* URI for the "wireless charging started" and "wired charging started" sound.
|
||||
* URI for the "wireless charging started" sound.
|
||||
* @hide
|
||||
*/
|
||||
public static final String CHARGING_STARTED_SOUND =
|
||||
public static final String WIRELESS_CHARGING_STARTED_SOUND =
|
||||
"wireless_charging_started_sound";
|
||||
|
||||
/**
|
||||
* URI for "wired charging started" sound.
|
||||
* @hide
|
||||
*/
|
||||
public static final String CHARGING_STARTED_SOUND = "charging_started_sound";
|
||||
|
||||
/**
|
||||
* Whether to play a sound for charging events.
|
||||
* @deprecated Use {@link android.provider.Settings.Secure#CHARGING_SOUNDS_ENABLED} instead
|
||||
|
||||
@@ -853,6 +853,7 @@ message GlobalSettingsProto {
|
||||
optional SettingProto low_battery_sounds_enabled = 12 [ (android.privacy).dest = DEST_AUTOMATIC ];
|
||||
optional SettingProto trusted = 13;
|
||||
optional SettingProto unlock = 14;
|
||||
optional SettingProto wireless_charging_started = 15;
|
||||
}
|
||||
optional Sounds sounds = 110;
|
||||
|
||||
|
||||
@@ -4357,4 +4357,8 @@
|
||||
create additional screen real estate outside beyond the keyboard. Note that the user needs
|
||||
to have a confirmed way to dismiss the keyboard when desired. -->
|
||||
<bool name="config_automotiveHideNavBarForKeyboard">false</bool>
|
||||
|
||||
<!-- Whether or not to show the built-in charging animation when the device begins charging
|
||||
wirelessly. -->
|
||||
<bool name="config_showBuiltinWirelessChargingAnim">true</bool>
|
||||
</resources>
|
||||
|
||||
@@ -3870,4 +3870,6 @@
|
||||
|
||||
<java-symbol type="bool" name="config_automotiveHideNavBarForKeyboard" />
|
||||
|
||||
<java-symbol type="bool" name="config_showBuiltinWirelessChargingAnim" />
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -1497,21 +1497,7 @@ class DatabaseHelper extends SQLiteOpenHelper {
|
||||
}
|
||||
|
||||
if (upgradeVersion == 94) {
|
||||
// Add wireless charging started sound setting
|
||||
if (mUserHandle == UserHandle.USER_SYSTEM) {
|
||||
db.beginTransaction();
|
||||
SQLiteStatement stmt = null;
|
||||
try {
|
||||
stmt = db.compileStatement("INSERT OR REPLACE INTO global(name,value)"
|
||||
+ " VALUES(?,?);");
|
||||
loadStringSetting(stmt, Settings.Global.CHARGING_STARTED_SOUND,
|
||||
R.string.def_wireless_charging_started_sound);
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
if (stmt != null) stmt.close();
|
||||
}
|
||||
}
|
||||
// charging sound moved to SettingsProvider version 184
|
||||
upgradeVersion = 95;
|
||||
}
|
||||
|
||||
@@ -2562,8 +2548,6 @@ class DatabaseHelper extends SQLiteOpenHelper {
|
||||
R.string.def_car_dock_sound);
|
||||
loadStringSetting(stmt, Settings.Global.CAR_UNDOCK_SOUND,
|
||||
R.string.def_car_undock_sound);
|
||||
loadStringSetting(stmt, Settings.Global.CHARGING_STARTED_SOUND,
|
||||
R.string.def_wireless_charging_started_sound);
|
||||
|
||||
loadIntegerSetting(stmt, Settings.Global.DOCK_AUDIO_MEDIA_ENABLED,
|
||||
R.integer.def_dock_audio_media_enabled);
|
||||
|
||||
@@ -1347,6 +1347,9 @@ class SettingsProtoDumpUtil {
|
||||
dumpSetting(s, p,
|
||||
Settings.Global.CHARGING_STARTED_SOUND,
|
||||
GlobalSettingsProto.Sounds.CHARGING_STARTED);
|
||||
dumpSetting(s, p,
|
||||
Settings.Global.WIRELESS_CHARGING_STARTED_SOUND,
|
||||
GlobalSettingsProto.Sounds.WIRELESS_CHARGING_STARTED);
|
||||
p.end(soundsToken);
|
||||
|
||||
final long soundTriggerToken = p.start(GlobalSettingsProto.SOUND_TRIGGER);
|
||||
|
||||
@@ -3206,7 +3206,7 @@ public class SettingsProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
private final class UpgradeController {
|
||||
private static final int SETTINGS_VERSION = 183;
|
||||
private static final int SETTINGS_VERSION = 184;
|
||||
|
||||
private final int mUserId;
|
||||
|
||||
@@ -3845,23 +3845,7 @@ public class SettingsProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
if (currentVersion == 155) {
|
||||
// Version 156: Set the default value for CHARGING_STARTED_SOUND.
|
||||
final SettingsState globalSettings = getGlobalSettingsLocked();
|
||||
final String oldValue = globalSettings.getSettingLocked(
|
||||
Global.CHARGING_STARTED_SOUND).getValue();
|
||||
final String oldDefault = getContext().getResources().getString(
|
||||
R.string.def_wireless_charging_started_sound);
|
||||
if (TextUtils.equals(null, oldValue)
|
||||
|| TextUtils.equals(oldValue, oldDefault)) {
|
||||
final String defaultValue = getContext().getResources().getString(
|
||||
R.string.def_charging_started_sound);
|
||||
if (!TextUtils.isEmpty(defaultValue)) {
|
||||
globalSettings.insertSettingLocked(
|
||||
Settings.Global.CHARGING_STARTED_SOUND, defaultValue,
|
||||
null, true, SettingsState.SYSTEM_PACKAGE_NAME);
|
||||
}
|
||||
|
||||
}
|
||||
// Version 156: migrated to version 184
|
||||
currentVersion = 156;
|
||||
}
|
||||
|
||||
@@ -4416,6 +4400,48 @@ public class SettingsProvider extends ContentProvider {
|
||||
currentVersion = 183;
|
||||
}
|
||||
|
||||
if (currentVersion == 183) {
|
||||
// Version 184: Set default values for WIRELESS_CHARGING_STARTED_SOUND
|
||||
// and CHARGING_STARTED_SOUND
|
||||
final SettingsState globalSettings = getGlobalSettingsLocked();
|
||||
|
||||
final String oldValueWireless = globalSettings.getSettingLocked(
|
||||
Global.WIRELESS_CHARGING_STARTED_SOUND).getValue();
|
||||
final String oldValueWired = globalSettings.getSettingLocked(
|
||||
Global.CHARGING_STARTED_SOUND).getValue();
|
||||
|
||||
final String defaultValueWireless = getContext().getResources().getString(
|
||||
R.string.def_wireless_charging_started_sound);
|
||||
final String defaultValueWired = getContext().getResources().getString(
|
||||
R.string.def_charging_started_sound);
|
||||
|
||||
// wireless charging sound
|
||||
if (oldValueWireless == null
|
||||
|| TextUtils.equals(oldValueWireless, defaultValueWired)) {
|
||||
if (!TextUtils.isEmpty(defaultValueWireless)) {
|
||||
globalSettings.insertSettingLocked(
|
||||
Global.WIRELESS_CHARGING_STARTED_SOUND, defaultValueWireless,
|
||||
null /* tag */, true /* makeDefault */,
|
||||
SettingsState.SYSTEM_PACKAGE_NAME);
|
||||
} else if (!TextUtils.isEmpty(defaultValueWired)) {
|
||||
// if the wireless sound is empty, use the wired charging sound
|
||||
globalSettings.insertSettingLocked(
|
||||
Global.WIRELESS_CHARGING_STARTED_SOUND, defaultValueWired,
|
||||
null /* tag */, true /* makeDefault */,
|
||||
SettingsState.SYSTEM_PACKAGE_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
// wired charging sound
|
||||
if (oldValueWired == null && !TextUtils.isEmpty(defaultValueWired)) {
|
||||
globalSettings.insertSettingLocked(
|
||||
Global.CHARGING_STARTED_SOUND, defaultValueWired,
|
||||
null /* tag */, true /* makeDefault */,
|
||||
SettingsState.SYSTEM_PACKAGE_NAME);
|
||||
}
|
||||
currentVersion = 184;
|
||||
}
|
||||
|
||||
// vXXX: Add new settings above this point.
|
||||
|
||||
if (currentVersion != newVersion) {
|
||||
|
||||
@@ -559,6 +559,7 @@ public class SettingsBackupTest {
|
||||
Settings.Global.WIFI_WATCHDOG_ON,
|
||||
Settings.Global.WIMAX_NETWORKS_AVAILABLE_NOTIFICATION_ON,
|
||||
Settings.Global.CHARGING_STARTED_SOUND,
|
||||
Settings.Global.WIRELESS_CHARGING_STARTED_SOUND,
|
||||
Settings.Global.WINDOW_ANIMATION_SCALE,
|
||||
Settings.Global.WTF_IS_FATAL,
|
||||
Settings.Global.ZEN_MODE,
|
||||
|
||||
@@ -94,16 +94,16 @@ public class Notifier {
|
||||
private static final int MSG_PROFILE_TIMED_OUT = 5;
|
||||
private static final int MSG_WIRED_CHARGING_STARTED = 6;
|
||||
|
||||
private static final long[] WIRELESS_VIBRATION_TIME = {
|
||||
private static final long[] CHARGING_VIBRATION_TIME = {
|
||||
40, 40, 40, 40, 40, 40, 40, 40, 40, // ramp-up sampling rate = 40ms
|
||||
40, 40, 40, 40, 40, 40, 40 // ramp-down sampling rate = 40ms
|
||||
};
|
||||
private static final int[] WIRELESS_VIBRATION_AMPLITUDE = {
|
||||
private static final int[] CHARGING_VIBRATION_AMPLITUDE = {
|
||||
1, 4, 11, 25, 44, 67, 91, 114, 123, // ramp-up amplitude (from 0 to 50%)
|
||||
103, 79, 55, 34, 17, 7, 2 // ramp-up amplitude
|
||||
};
|
||||
private static final VibrationEffect WIRELESS_CHARGING_VIBRATION_EFFECT =
|
||||
VibrationEffect.createWaveform(WIRELESS_VIBRATION_TIME, WIRELESS_VIBRATION_AMPLITUDE,
|
||||
private static final VibrationEffect CHARGING_VIBRATION_EFFECT =
|
||||
VibrationEffect.createWaveform(CHARGING_VIBRATION_TIME, CHARGING_VIBRATION_AMPLITUDE,
|
||||
-1);
|
||||
private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
@@ -130,6 +130,10 @@ public class Notifier {
|
||||
// True if the device should suspend when the screen is off due to proximity.
|
||||
private final boolean mSuspendWhenScreenOffDueToProximityConfig;
|
||||
|
||||
// True if the device should show the wireless charging animation when the device
|
||||
// begins charging wirelessly
|
||||
private final boolean mShowWirelessChargingAnimationConfig;
|
||||
|
||||
// The current interactive state. This is set as soon as an interactive state
|
||||
// transition begins so as to capture the reason that it happened. At some point
|
||||
// this state will propagate to the pending state then eventually to the
|
||||
@@ -182,6 +186,8 @@ public class Notifier {
|
||||
|
||||
mSuspendWhenScreenOffDueToProximityConfig = context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_suspendWhenScreenOffDueToProximity);
|
||||
mShowWirelessChargingAnimationConfig = context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_showBuiltinWirelessChargingAnim);
|
||||
|
||||
// Initialize interactive state for battery stats.
|
||||
try {
|
||||
@@ -755,35 +761,45 @@ public class Notifier {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If enabled, plays a sound and/or vibration when wireless or non-wireless charging has started
|
||||
*/
|
||||
private void playChargingStartedFeedback(@UserIdInt int userId) {
|
||||
playChargingStartedVibration(userId);
|
||||
private void playChargingStartedFeedback(@UserIdInt int userId, boolean wireless) {
|
||||
if (!isChargingFeedbackEnabled(userId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// vibrate
|
||||
final boolean vibrate = Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.CHARGING_VIBRATION_ENABLED, 1, userId) != 0;
|
||||
if (vibrate) {
|
||||
mVibrator.vibrate(CHARGING_VIBRATION_EFFECT, VIBRATION_ATTRIBUTES);
|
||||
}
|
||||
|
||||
// play sound
|
||||
final String soundPath = Settings.Global.getString(mContext.getContentResolver(),
|
||||
Settings.Global.CHARGING_STARTED_SOUND);
|
||||
if (isChargingFeedbackEnabled(userId) && soundPath != null) {
|
||||
final Uri soundUri = Uri.parse("file://" + soundPath);
|
||||
if (soundUri != null) {
|
||||
final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri);
|
||||
if (sfx != null) {
|
||||
sfx.setStreamType(AudioManager.STREAM_SYSTEM);
|
||||
sfx.play();
|
||||
}
|
||||
wireless ? Settings.Global.WIRELESS_CHARGING_STARTED_SOUND
|
||||
: Settings.Global.CHARGING_STARTED_SOUND);
|
||||
final Uri soundUri = Uri.parse("file://" + soundPath);
|
||||
if (soundUri != null) {
|
||||
final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri);
|
||||
if (sfx != null) {
|
||||
sfx.setStreamType(AudioManager.STREAM_SYSTEM);
|
||||
sfx.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showWirelessChargingStarted(int batteryLevel, @UserIdInt int userId) {
|
||||
playChargingStartedFeedback(userId);
|
||||
if (mStatusBarManagerInternal != null) {
|
||||
// play sounds + haptics
|
||||
playChargingStartedFeedback(userId, true /* wireless */);
|
||||
|
||||
// show animation
|
||||
if (mShowWirelessChargingAnimationConfig && mStatusBarManagerInternal != null) {
|
||||
mStatusBarManagerInternal.showChargingAnimation(batteryLevel);
|
||||
}
|
||||
mSuspendBlocker.release();
|
||||
}
|
||||
|
||||
private void showWiredChargingStarted(@UserIdInt int userId) {
|
||||
playChargingStartedFeedback(userId);
|
||||
playChargingStartedFeedback(userId, false /* wireless */);
|
||||
mSuspendBlocker.release();
|
||||
}
|
||||
|
||||
@@ -791,14 +807,6 @@ public class Notifier {
|
||||
mTrustManager.setDeviceLockedForUser(userId, true /*locked*/);
|
||||
}
|
||||
|
||||
private void playChargingStartedVibration(@UserIdInt int userId) {
|
||||
final boolean vibrateEnabled = Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.CHARGING_VIBRATION_ENABLED, 1, userId) != 0;
|
||||
if (vibrateEnabled && isChargingFeedbackEnabled(userId)) {
|
||||
mVibrator.vibrate(WIRELESS_CHARGING_VIBRATION_EFFECT, VIBRATION_ATTRIBUTES);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isChargingFeedbackEnabled(@UserIdInt int userId) {
|
||||
final boolean enabled = Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.CHARGING_SOUNDS_ENABLED, 1, userId) != 0;
|
||||
|
||||
Reference in New Issue
Block a user