Skip to content

Commit bffc3d1

Browse files
author
Eric Laurent
committed
Silent and Vibrate mode clean up
Clean up related to new Vibration policy. The vibrate behavior is now only derived from: - presence of a vibrator on the device - current ringer mode selected: NORMAL, VIBRATE or SILENT If no vibrator is present the ringer mode can only be NORMAL or SILENT. The control of ringer mode via volume keys when volume keys control the "master" stream type (RING on phones, MUSIC on tablets) is as follows: If a vibrator is present: VOL- and volume equals 1: NORMAL => VIBRATE VOL- and volume equals 0 and not continuous press: VIBRATE => SILENT VOL+ and in SILENT mode: SILENT => VIBRATE VOL+ and in VIBRATE mode: VIBRATE => NORMAL, volume = 1 If no vibrator is present: VOL- and volume equals 0 and not continuous press: NORMAL => SILENT VOL+ and in SILENT mode: SILENT => NORMAL, volume = 0 VIBRATE_ON and VIBRATE_IN_SILENT settings are not stored/retreived any more. AudioService checks and corrects ringer mode and stream volumes if necessary when reading from DB at boot time. Also: Added dump for stream volumes in AudioService. Added device names missing in AudioSystem for USB accessory and USB device. Issue: 6036529 Issue: 6414950 Issue: 6448163 Change-Id: I77fb821ec63e4e566320cac2701b4ac466e86aef
1 parent c2182c6 commit bffc3d1

File tree

9 files changed

+196
-120
lines changed

9 files changed

+196
-120
lines changed

core/java/android/provider/Settings.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,9 @@ public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) {
15571557
* will likely be removed in a future release with support for
15581558
* audio/vibe feedback profiles.
15591559
*
1560+
* Not used anymore. On devices with vibrator, the user explicitly selects
1561+
* silent or vibrate mode.
1562+
* Kept for use by legacy database upgrade code in DatabaseHelper.
15601563
* @hide
15611564
*/
15621565
public static final String VIBRATE_IN_SILENT = "vibrate_in_silent";
@@ -1983,7 +1986,6 @@ public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) {
19831986
SCREEN_BRIGHTNESS,
19841987
SCREEN_BRIGHTNESS_MODE,
19851988
SCREEN_AUTO_BRIGHTNESS_ADJ,
1986-
VIBRATE_ON,
19871989
VIBRATE_INPUT_DEVICES,
19881990
MODE_RINGER,
19891991
MODE_RINGER_STREAMS_AFFECTED,
@@ -2002,7 +2004,6 @@ public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) {
20022004
VOLUME_ALARM + APPEND_FOR_LAST_AUDIBLE,
20032005
VOLUME_NOTIFICATION + APPEND_FOR_LAST_AUDIBLE,
20042006
VOLUME_BLUETOOTH_SCO + APPEND_FOR_LAST_AUDIBLE,
2005-
VIBRATE_IN_SILENT,
20062007
TEXT_AUTO_REPLACE,
20072008
TEXT_AUTO_CAPS,
20082009
TEXT_AUTO_PUNCTUATE,

media/java/android/media/AudioService.java

Lines changed: 152 additions & 84 deletions
Large diffs are not rendered by default.

media/java/android/media/AudioSystem.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ private static void errorCallbackFromNative(int error)
260260
public static final String DEVICE_OUT_AUX_DIGITAL_NAME = "aux_digital";
261261
public static final String DEVICE_OUT_ANLG_DOCK_HEADSET_NAME = "analog_dock";
262262
public static final String DEVICE_OUT_DGTL_DOCK_HEADSET_NAME = "digital_dock";
263+
public static final String DEVICE_OUT_USB_ACCESSORY_NAME = "usb_accessory";
264+
public static final String DEVICE_OUT_USB_DEVICE_NAME = "usb_device";
263265

264266
public static String getDeviceName(int device)
265267
{
@@ -290,6 +292,10 @@ public static String getDeviceName(int device)
290292
return DEVICE_OUT_ANLG_DOCK_HEADSET_NAME;
291293
case DEVICE_OUT_DGTL_DOCK_HEADSET:
292294
return DEVICE_OUT_DGTL_DOCK_HEADSET_NAME;
295+
case DEVICE_OUT_USB_ACCESSORY:
296+
return DEVICE_OUT_USB_ACCESSORY_NAME;
297+
case DEVICE_OUT_USB_DEVICE:
298+
return DEVICE_OUT_USB_DEVICE_NAME;
293299
case DEVICE_IN_DEFAULT:
294300
default:
295301
return "";

packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
6363
// database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
6464
// is properly propagated through your change. Not doing so will result in a loss of user
6565
// settings.
66-
private static final int DATABASE_VERSION = 76;
66+
private static final int DATABASE_VERSION = 77;
6767

6868
private Context mContext;
6969

@@ -1031,6 +1031,23 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
10311031
upgradeVersion = 76;
10321032
}
10331033

1034+
/************* The following are Jelly Bean changes ************/
1035+
1036+
if (upgradeVersion == 76) {
1037+
// Removed VIBRATE_IN_SILENT setting
1038+
db.beginTransaction();
1039+
try {
1040+
db.execSQL("DELETE FROM system WHERE name='"
1041+
+ Settings.System.VIBRATE_IN_SILENT + "'");
1042+
db.setTransactionSuccessful();
1043+
} finally {
1044+
db.endTransaction();
1045+
}
1046+
1047+
upgradeVersion = 77;
1048+
}
1049+
1050+
10341051
// *** Remember to update DATABASE_VERSION above!
10351052

10361053
if (upgradeVersion != currentVersion) {
@@ -1311,8 +1328,6 @@ private void loadVolumeLevels(SQLiteDatabase db) {
13111328
loadSetting(stmt, Settings.System.MODE_RINGER,
13121329
AudioManager.RINGER_MODE_NORMAL);
13131330

1314-
loadVibrateSetting(db, false);
1315-
13161331
// By default:
13171332
// - ringtones, notification, system and music streams are affected by ringer mode
13181333
// on non voice capable devices (tablets)
@@ -1433,9 +1448,6 @@ private void loadSystemSettings(SQLiteDatabase db) {
14331448

14341449
loadUISoundEffectsSettings(stmt);
14351450

1436-
loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
1437-
R.bool.def_vibrate_in_silent);
1438-
14391451
loadIntegerSetting(stmt, Settings.System.POINTER_SPEED,
14401452
R.integer.def_pointer_speed);
14411453

packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ public class SettingsHelper {
4343
private IContentService mContentService;
4444
private IPowerManager mPowerManager;
4545

46-
private boolean mSilent;
47-
private boolean mVibrate;
48-
4946
public SettingsHelper(Context context) {
5047
mContext = context;
5148
mAudioManager = (AudioManager) context
@@ -119,18 +116,6 @@ private void setBrightness(int brightness) {
119116
}
120117
}
121118

122-
private void setRingerMode() {
123-
if (mSilent) {
124-
mAudioManager.setRingerMode(mVibrate ? AudioManager.RINGER_MODE_VIBRATE :
125-
AudioManager.RINGER_MODE_SILENT);
126-
} else {
127-
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
128-
mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
129-
mVibrate ? AudioManager.VIBRATE_SETTING_ON
130-
: AudioManager.VIBRATE_SETTING_OFF);
131-
}
132-
}
133-
134119
byte[] getLocaleData() {
135120
Configuration conf = mContext.getResources().getConfiguration();
136121
final Locale loc = conf.locale;

packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) ||
122122
action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
123123
updateBluetooth(intent);
124124
}
125-
else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
126-
action.equals(AudioManager.VIBRATE_SETTING_CHANGED_ACTION)) {
125+
else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
127126
updateVolume();
128127
}
129128
else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
@@ -144,7 +143,6 @@ public PhoneStatusBarPolicy(Context context) {
144143
filter.addAction(Intent.ACTION_ALARM_CHANGED);
145144
filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED);
146145
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
147-
filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION);
148146
filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
149147
filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
150148
filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
@@ -238,7 +236,7 @@ private final void updateVolume() {
238236

239237
final int iconId;
240238
String contentDescription = null;
241-
if (audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER)) {
239+
if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
242240
iconId = R.drawable.stat_sys_ringer_vibrate;
243241
contentDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
244242
} else {

packages/SystemUI/src/com/android/systemui/statusbar/policy/VolumeController.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.content.Context;
2121
import android.os.RemoteException;
2222
import android.os.ServiceManager;
23+
import android.os.Vibrator;
2324
import android.media.AudioManager;
2425
import android.provider.Settings;
2526
import android.util.Slog;
@@ -36,10 +37,16 @@ public class VolumeController implements ToggleSlider.Listener {
3637

3738
private boolean mMute;
3839
private int mVolume;
40+
// Is there a vibrator
41+
private final boolean mHasVibrator;
3942

4043
public VolumeController(Context context, ToggleSlider control) {
4144
mContext = context;
4245
mControl = control;
46+
47+
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
48+
mHasVibrator = vibrator == null ? false : vibrator.hasVibrator();
49+
4350
mAudioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
4451

4552
mMute = mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
@@ -54,10 +61,8 @@ public VolumeController(Context context, ToggleSlider control) {
5461
public void onChanged(ToggleSlider view, boolean tracking, boolean mute, int level) {
5562
if (!tracking) {
5663
if (mute) {
57-
boolean vibeInSilent = (1 == Settings.System.getInt(mContext.getContentResolver(),
58-
Settings.System.VIBRATE_IN_SILENT, 1));
5964
mAudioManager.setRingerMode(
60-
vibeInSilent ? AudioManager.RINGER_MODE_VIBRATE
65+
mHasVibrator ? AudioManager.RINGER_MODE_VIBRATE
6166
: AudioManager.RINGER_MODE_SILENT);
6267
} else {
6368
mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

policy/src/com/android/internal/policy/impl/LockScreen.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import android.content.Intent;
3535
import android.content.res.Configuration;
3636
import android.content.res.Resources;
37+
import android.os.Vibrator;
3738
import android.view.KeyEvent;
3839
import android.view.LayoutInflater;
3940
import android.view.View;
@@ -82,6 +83,8 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
8283
private boolean mCameraDisabled;
8384
private boolean mSearchDisabled;
8485
private SearchManager mSearchManager;
86+
// Is there a vibrator
87+
private final boolean mHasVibrator;
8588

8689
InfoCallbackImpl mInfoCallback = new InfoCallbackImpl() {
8790

@@ -385,11 +388,7 @@ private void toggleRingMode() {
385388
// toggle silent mode
386389
mSilentMode = !mSilentMode;
387390
if (mSilentMode) {
388-
final boolean vibe = (Settings.System.getInt(
389-
mContext.getContentResolver(),
390-
Settings.System.VIBRATE_IN_SILENT, 1) == 1);
391-
392-
mAudioManager.setRingerMode(vibe
391+
mAudioManager.setRingerMode(mHasVibrator
393392
? AudioManager.RINGER_MODE_VIBRATE
394393
: AudioManager.RINGER_MODE_SILENT);
395394
} else {
@@ -451,6 +450,8 @@ private boolean shouldEnableMenuKey() {
451450
setFocusableInTouchMode(true);
452451
setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
453452

453+
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
454+
mHasVibrator = vibrator == null ? false : vibrator.hasVibrator();
454455
mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
455456
mSilentMode = isSilentMode();
456457
mUnlockWidget = findViewById(R.id.unlock_widget);

services/java/com/android/server/NotificationManagerService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ public void enqueueNotificationInternal(String pkg, int callingUid, int callingP
10461046
final boolean useDefaultVibrate =
10471047
(notification.defaults & Notification.DEFAULT_VIBRATE) != 0;
10481048
if ((useDefaultVibrate || notification.vibrate != null)
1049-
&& audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_NOTIFICATION)) {
1049+
&& !(audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT)) {
10501050
mVibrateNotification = r;
10511051

10521052
mVibrator.vibrate(useDefaultVibrate ? DEFAULT_VIBRATE_PATTERN

0 commit comments

Comments
 (0)