Skip to content

Commit ced11a5

Browse files
Mike LockwoodAndroid (Google) Code Review
authored andcommitted
Merge changes I35a76a27,I04bb7ad4,If38a1a10,Ice5be6e5,I009e443f,I968ddf90,I69d4e518,I09b1dfc9
* changes: Merge commit '74803dc' add config_bluetooth_default_profiles config var and use it to disable bt profiles Do not allow Surface creation on machines without SurfaceFlinger We will fail later anyways, but this change makes it much easier to track down places where we are inadvertently doing operations that depend on the flinger. fix setting only usb mode Detect (at runtime) kernel support for the "hdmi_audio" switch. Add a config resource to disable key-chord screenshotting Do not assume that there is always a running activity (Necessary for headless devices) Add batch volume adjust support to adjustMasterVolume() in AudioManager and AudioService.
2 parents 1c8e0a0 + 1b6989c commit ced11a5

File tree

13 files changed

+342
-108
lines changed

13 files changed

+342
-108
lines changed

core/java/android/server/BluetoothService.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import android.content.Intent;
4747
import android.content.IntentFilter;
4848
import android.content.SharedPreferences;
49+
import android.content.res.Resources;
4950
import android.os.Binder;
5051
import android.os.Handler;
5152
import android.os.IBinder;
@@ -554,27 +555,32 @@ private synchronized void addReservedSdpRecords(final ArrayList<ParcelUuid> uuid
554555
private synchronized void updateSdpRecords() {
555556
ArrayList<ParcelUuid> uuids = new ArrayList<ParcelUuid>();
556557

558+
Resources R = mContext.getResources();
559+
557560
// Add the default records
558-
uuids.add(BluetoothUuid.HSP_AG);
559-
uuids.add(BluetoothUuid.ObexObjectPush);
561+
if (R.getBoolean(com.android.internal.R.bool.config_bluetooth_default_profiles)) {
562+
uuids.add(BluetoothUuid.HSP_AG);
563+
uuids.add(BluetoothUuid.ObexObjectPush);
564+
}
560565

561-
if (mContext.getResources().
562-
getBoolean(com.android.internal.R.bool.config_voice_capable)) {
566+
if (R.getBoolean(com.android.internal.R.bool.config_voice_capable)) {
563567
uuids.add(BluetoothUuid.Handsfree_AG);
564568
uuids.add(BluetoothUuid.PBAP_PSE);
565569
}
566570

567571
// Add SDP records for profiles maintained by Android userspace
568572
addReservedSdpRecords(uuids);
569573

570-
// Enable profiles maintained by Bluez userspace.
571-
setBluetoothTetheringNative(true, BluetoothPanProfileHandler.NAP_ROLE,
572-
BluetoothPanProfileHandler.NAP_BRIDGE);
574+
if (R.getBoolean(com.android.internal.R.bool.config_bluetooth_default_profiles)) {
575+
// Enable profiles maintained by Bluez userspace.
576+
setBluetoothTetheringNative(true, BluetoothPanProfileHandler.NAP_ROLE,
577+
BluetoothPanProfileHandler.NAP_BRIDGE);
573578

574-
// Add SDP records for profiles maintained by Bluez userspace
575-
uuids.add(BluetoothUuid.AudioSource);
576-
uuids.add(BluetoothUuid.AvrcpTarget);
577-
uuids.add(BluetoothUuid.NAP);
579+
// Add SDP records for profiles maintained by Bluez userspace
580+
uuids.add(BluetoothUuid.AudioSource);
581+
uuids.add(BluetoothUuid.AvrcpTarget);
582+
uuids.add(BluetoothUuid.NAP);
583+
}
578584

579585
// Cannot cast uuids.toArray directly since ParcelUuid is parcelable
580586
mAdapterUuids = new ParcelUuid[uuids.size()];

core/java/android/view/Surface.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.graphics.*;
2121
import android.os.Parcelable;
2222
import android.os.Parcel;
23+
import android.os.SystemProperties;
2324
import android.util.Log;
2425

2526
/**
@@ -35,6 +36,15 @@ public class Surface implements Parcelable {
3536
public static final int ROTATION_180 = 2;
3637
public static final int ROTATION_270 = 3;
3738

39+
private static final boolean headless = "1".equals(
40+
SystemProperties.get("ro.config.headless", "0"));
41+
42+
private static void checkHeadless() {
43+
if(headless) {
44+
throw new UnsupportedOperationException("Device is headless");
45+
}
46+
}
47+
3848
/**
3949
* Create Surface from a {@link SurfaceTexture}.
4050
*
@@ -46,6 +56,8 @@ public class Surface implements Parcelable {
4656
* Surface.
4757
*/
4858
public Surface(SurfaceTexture surfaceTexture) {
59+
checkHeadless();
60+
4961
if (DEBUG_RELEASE) {
5062
mCreationStack = new Exception();
5163
}
@@ -244,6 +256,8 @@ public OutOfResourcesException(String name) {
244256
public Surface(SurfaceSession s,
245257
int pid, int display, int w, int h, int format, int flags)
246258
throws OutOfResourcesException {
259+
checkHeadless();
260+
247261
if (DEBUG_RELEASE) {
248262
mCreationStack = new Exception();
249263
}
@@ -255,6 +269,8 @@ public Surface(SurfaceSession s,
255269
public Surface(SurfaceSession s,
256270
int pid, String name, int display, int w, int h, int format, int flags)
257271
throws OutOfResourcesException {
272+
checkHeadless();
273+
258274
if (DEBUG_RELEASE) {
259275
mCreationStack = new Exception();
260276
}
@@ -269,6 +285,8 @@ public Surface(SurfaceSession s,
269285
* @hide
270286
*/
271287
public Surface() {
288+
checkHeadless();
289+
272290
if (DEBUG_RELEASE) {
273291
mCreationStack = new Exception();
274292
}

core/res/res/values/config.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@
308308
<!-- If this is true, the screen will fade off. -->
309309
<bool name="config_animateScreenLights">true</bool>
310310

311+
<!-- If this is true, key chords can be used to take a screenshot on the device. -->
312+
<bool name="config_enableScreenshotChord">true</bool>
313+
311314
<!-- If true, the screen can be rotated via the accelerometer in all 4
312315
rotations as the default behavior. -->
313316
<bool name="config_allowAllRotations">false</bool>
@@ -632,6 +635,10 @@
632635
cell broadcasting sms, and MMS. -->
633636
<bool name="config_sms_capable">true</bool>
634637

638+
<!-- Enable/disable default bluetooth profiles:
639+
HSP_AG, ObexObjectPush, Audio, NAP -->
640+
<bool name="config_bluetooth_default_profiles">true</bool>
641+
635642
<!-- IP address of the dns server to use if nobody else suggests one -->
636643
<string name="config_default_dns_server" translatable="false">8.8.8.8</string>
637644

core/res/res/values/public.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@
244244
<java-symbol type="bool" name="config_useMasterVolume" />
245245
<java-symbol type="bool" name="config_enableWallpaperService" />
246246
<java-symbol type="bool" name="config_sendAudioBecomingNoisy" />
247+
<java-symbol type="bool" name="config_enableScreenshotChord" />
248+
<java-symbol type="bool" name="config_bluetooth_default_profiles" />
247249

248250
<java-symbol type="integer" name="config_cursorWindowSize" />
249251
<java-symbol type="integer" name="config_longPressOnPowerBehavior" />

media/java/android/media/AudioManager.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,16 +608,15 @@ public void adjustSuggestedStreamVolume(int direction, int suggestedStreamType,
608608
* Adjusts the master volume for the device's audio amplifier.
609609
* <p>
610610
*
611-
* @param direction The direction to adjust the volume. One of
612-
* {@link #ADJUST_LOWER}, {@link #ADJUST_RAISE}, or
613-
* {@link #ADJUST_SAME}.
611+
* @param steps The number of volume steps to adjust. A positive
612+
* value will raise the volume.
614613
* @param flags One or more flags.
615614
* @hide
616615
*/
617-
public void adjustMasterVolume(int direction, int flags) {
616+
public void adjustMasterVolume(int steps, int flags) {
618617
IAudioService service = getService();
619618
try {
620-
service.adjustMasterVolume(direction, flags);
619+
service.adjustMasterVolume(steps, flags);
621620
} catch (RemoteException e) {
622621
Log.e(TAG, "Dead object in adjustMasterVolume", e);
623622
}

media/java/android/media/AudioService.java

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ public class AudioService extends IAudioService.Stub {
159159
// but to support integer based AudioManager API we translate it to 0 - 100
160160
private static final int MAX_MASTER_VOLUME = 100;
161161

162+
// Maximum volume adjust steps allowed in a single batch call.
163+
private static final int MAX_BATCH_VOLUME_ADJUST_STEPS = 4;
164+
162165
/* Sound effect file names */
163166
private static final String SOUND_EFFECTS_PATH = "/media/audio/ui/";
164167
private static final String[] SOUND_EFFECT_FILES = new String[] {
@@ -619,38 +622,19 @@ public void adjustStreamVolume(int streamType, int direction, int flags) {
619622
}
620623

621624
/** @see AudioManager#adjustMasterVolume(int) */
622-
public void adjustMasterVolume(int direction, int flags) {
623-
ensureValidDirection(direction);
625+
public void adjustMasterVolume(int steps, int flags) {
626+
ensureValidSteps(steps);
624627
int volume = Math.round(AudioSystem.getMasterVolume() * MAX_MASTER_VOLUME);
625628
int delta = 0;
626-
627-
if (direction == AudioManager.ADJUST_RAISE) {
628-
// This is the default value if we make it to the end
629-
delta = mMasterVolumeRamp[1];
630-
// If we're raising the volume move down the ramp array until we
631-
// find the volume we're above and use that groups delta.
632-
for (int i = mMasterVolumeRamp.length - 1; i > 1; i -= 2) {
633-
if (volume >= mMasterVolumeRamp[i - 1]) {
634-
delta = mMasterVolumeRamp[i];
635-
break;
636-
}
637-
}
638-
} else if (direction == AudioManager.ADJUST_LOWER){
639-
int length = mMasterVolumeRamp.length;
640-
// This is the default value if we make it to the end
641-
delta = -mMasterVolumeRamp[length - 1];
642-
// If we're lowering the volume move up the ramp array until we
643-
// find the volume we're below and use the group below it's delta
644-
for (int i = 2; i < length; i += 2) {
645-
if (volume <= mMasterVolumeRamp[i]) {
646-
delta = -mMasterVolumeRamp[i - 1];
647-
break;
648-
}
649-
}
629+
int numSteps = Math.abs(steps);
630+
int direction = steps > 0 ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER;
631+
for (int i = 0; i < numSteps; ++i) {
632+
delta = findVolumeDelta(direction, volume);
633+
volume += delta;
650634
}
651635

652-
// Log.d(TAG, "adjustMasterVolume volume: " + volume + " delta: " + delta + " direction: " + direction);
653-
setMasterVolume(volume + delta, flags);
636+
//Log.d(TAG, "adjustMasterVolume volume: " + volume + " steps: " + steps);
637+
setMasterVolume(volume, flags);
654638
}
655639

656640
/** @see AudioManager#setStreamVolume(int, int, int) */
@@ -691,6 +675,41 @@ public void setStreamVolume(int streamType, int index, int flags) {
691675
sendVolumeUpdate(streamType, oldIndex, index, flags);
692676
}
693677

678+
private int findVolumeDelta(int direction, int volume) {
679+
int delta = 0;
680+
if (direction == AudioManager.ADJUST_RAISE) {
681+
if (volume == MAX_MASTER_VOLUME) {
682+
return 0;
683+
}
684+
// This is the default value if we make it to the end
685+
delta = mMasterVolumeRamp[1];
686+
// If we're raising the volume move down the ramp array until we
687+
// find the volume we're above and use that groups delta.
688+
for (int i = mMasterVolumeRamp.length - 1; i > 1; i -= 2) {
689+
if (volume >= mMasterVolumeRamp[i - 1]) {
690+
delta = mMasterVolumeRamp[i];
691+
break;
692+
}
693+
}
694+
} else if (direction == AudioManager.ADJUST_LOWER){
695+
if (volume == 0) {
696+
return 0;
697+
}
698+
int length = mMasterVolumeRamp.length;
699+
// This is the default value if we make it to the end
700+
delta = -mMasterVolumeRamp[length - 1];
701+
// If we're lowering the volume move up the ramp array until we
702+
// find the volume we're below and use the group below it's delta
703+
for (int i = 2; i < length; i += 2) {
704+
if (volume <= mMasterVolumeRamp[i]) {
705+
delta = -mMasterVolumeRamp[i - 1];
706+
break;
707+
}
708+
}
709+
}
710+
return delta;
711+
}
712+
694713
// UI update and Broadcast Intent
695714
private void sendVolumeUpdate(int streamType, int oldIndex, int index, int flags) {
696715
if (!mVoiceCapable && (streamType == AudioSystem.STREAM_RING)) {
@@ -1871,6 +1890,12 @@ private void ensureValidDirection(int direction) {
18711890
}
18721891
}
18731892

1893+
private void ensureValidSteps(int steps) {
1894+
if (Math.abs(steps) > MAX_BATCH_VOLUME_ADJUST_STEPS) {
1895+
throw new IllegalArgumentException("Bad volume adjust steps " + steps);
1896+
}
1897+
}
1898+
18741899
private void ensureValidStreamType(int streamType) {
18751900
if (streamType < 0 || streamType >= mStreamStates.length) {
18761901
throw new IllegalArgumentException("Bad stream type " + streamType);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ public void onInputEvent(InputEvent event) {
463463
// Screenshot trigger states
464464
// Time to volume and power must be pressed within this interval of each other.
465465
private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
466+
private boolean mScreenshotChordEnabled;
466467
private boolean mVolumeDownKeyTriggered;
467468
private long mVolumeDownKeyTime;
468469
private boolean mVolumeDownKeyConsumedByScreenshotChord;
@@ -636,7 +637,8 @@ private void cancelPendingPowerKeyAction() {
636637
}
637638

638639
private void interceptScreenshotChord() {
639-
if (mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
640+
if (mScreenshotChordEnabled
641+
&& mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
640642
final long now = SystemClock.uptimeMillis();
641643
if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
642644
&& now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
@@ -882,6 +884,9 @@ public void init(Context context, IWindowManager windowManager,
882884
mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
883885
com.android.internal.R.array.config_safeModeEnabledVibePattern);
884886

887+
mScreenshotChordEnabled = mContext.getResources().getBoolean(
888+
com.android.internal.R.bool.config_enableScreenshotChord);
889+
885890
// Controls rotation and the like.
886891
initializeHdmiState();
887892

@@ -1574,7 +1579,7 @@ public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int p
15741579
// If we think we might have a volume down & power key chord on the way
15751580
// but we're not sure, then tell the dispatcher to wait a little while and
15761581
// try again later before dispatching.
1577-
if ((flags & KeyEvent.FLAG_FALLBACK) == 0) {
1582+
if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
15781583
if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
15791584
final long now = SystemClock.uptimeMillis();
15801585
final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;

0 commit comments

Comments
 (0)