changeset in /hg/pulseaudio: 2008-10-10 Omair Majid <omajid at redh...
Omair Majid
omajid at redhat.com
Fri Oct 10 08:10:37 PDT 2008
changeset 63fe20298326 in /hg/pulseaudio
details: http://icedtea.classpath.org/hg/pulseaudio?cmd=changeset;node=63fe20298326
description:
2008-10-10 Omair Majid <omajid at redhat.com>
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java
(close): Check for audio permissions.
(open): Likewise.
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java
(open): Removed FIXME for security.
(close): Likewise.
* src/java/org/classpath/icedtea/pulseaudio/Mixer.java
(getLine): Check for permissions before returning a line.
(getSourceLines): Check for permissions.
(getTargetLines): Likewise.
(close): Likewise.
(openRemote): Likewise.
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java
(PulseAudioPort): Dont open the port by default.
(open): Removed FIXME.
(close): Likewise.
* src/java/org/classpath/icedtea/pulseaudio/PulseAUdioSourceDataLine.j.ava
(open): Check for permissions.
(close): Likewise.
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java
(open): Likewise.
(close): Likewise.
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
(open): Likewise.
(close): Likewise.
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java
(open): Likewise.
(close): Likewise.
* unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourcePortTest.java
(testControls): Open and close the ports.
* unittests/org/classpath/icedtea/pulseaudio/PulseAUdioTargetPortTest.java
(testControls): Likewise.
diffstat:
10 files changed, 132 insertions(+), 59 deletions(-)
src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java | 23 ++-
src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java | 7 -
src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java | 65 ++++++++--
src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java | 14 --
src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java | 12 +
src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java | 13 +-
src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java | 16 +-
src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java | 33 +++--
unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourcePortTest.java | 4
unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetPortTest.java | 4
diffs (truncated from 510 to 500 lines):
diff -r d4676ea1be88 -r 63fe20298326 src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Thu Oct 09 17:28:36 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Fri Oct 10 11:10:27 2008 -0400
@@ -41,6 +41,7 @@ import java.io.IOException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioPermission;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
@@ -229,12 +230,15 @@ public class PulseAudioClip extends Puls
@Override
public void close() {
+
+ /* check for permission to play audio */
+ AudioPermission perm = new AudioPermission("play", null);
+ perm.checkGuard(null);
+
if (!isOpen) {
throw new IllegalStateException("line already closed");
}
- // FIXME security
-
clipThread.interrupt();
try {
@@ -358,10 +362,11 @@ public class PulseAudioClip extends Puls
throw new IllegalStateException("Line not open");
}
- if ( count < 0 && count != LOOP_CONTINUOUSLY) {
- throw new IllegalArgumentException("invalid value for count:" + count);
- }
-
+ if (count < 0 && count != LOOP_CONTINUOUSLY) {
+ throw new IllegalArgumentException("invalid value for count:"
+ + count);
+ }
+
if (clipThread.isAlive() && count != 0) {
// Do nothing; behavior not specified by the Java API
return;
@@ -392,8 +397,10 @@ public class PulseAudioClip extends Puls
public void open(AudioFormat format, byte[] data, int offset, int bufferSize)
throws LineUnavailableException {
- // FIXME security
-
+ /* check for permission to play audio */
+ AudioPermission perm = new AudioPermission("play", null);
+ perm.checkGuard(null);
+
super.open(format);
this.data = new byte[bufferSize];
System.arraycopy(data, offset, this.data, 0, bufferSize);
diff -r d4676ea1be88 -r 63fe20298326 src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Thu Oct 09 17:28:36 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Fri Oct 10 11:10:27 2008 -0400
@@ -84,8 +84,6 @@ public abstract class PulseAudioDataLine
if (isOpen) {
throw new IllegalStateException("Line is already open");
}
-
- // FIXME security
createStream(format);
addStreamListeners();
@@ -290,8 +288,6 @@ public abstract class PulseAudioDataLine
"Line must be open for close() to work");
}
- // FIXME security
-
synchronized (eventLoop.threadLock) {
stream.disconnect();
}
@@ -310,7 +306,7 @@ public abstract class PulseAudioDataLine
isStarted = false;
}
-
+
public void reconnectforSynchronization(Stream masterStream)
throws LineUnavailableException {
sendEvents = false;
@@ -353,7 +349,6 @@ public abstract class PulseAudioDataLine
isStarted = true;
}
-
public synchronized void stop() {
if (!isOpen) {
diff -r d4676ea1be88 -r 63fe20298326 src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java Thu Oct 09 17:28:36 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java Fri Oct 10 11:10:27 2008 -0400
@@ -49,6 +49,7 @@ import java.util.concurrent.Semaphore;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioPermission;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.Control;
@@ -266,8 +267,6 @@ public class PulseAudioMixer implements
@Override
public Line getLine(Line.Info info) throws LineUnavailableException {
- // FIXME security!
-
if (!isLineSupported(info)) {
throw new IllegalArgumentException("Line unsupported: " + info);
}
@@ -302,16 +301,28 @@ public class PulseAudioMixer implements
}
if ((info.getLineClass() == SourceDataLine.class)) {
+ /* check for permission to play audio */
+ AudioPermission perm = new AudioPermission("play", null);
+ perm.checkGuard(null);
+
return new PulseAudioSourceDataLine(eventLoop, formats,
defaultFormat);
}
if ((info.getLineClass() == TargetDataLine.class)) {
+ /* check for permission to play audio */
+ AudioPermission perm = new AudioPermission("record", null);
+ perm.checkGuard(null);
+
return new PulseAudioTargetDataLine(eventLoop, formats,
defaultFormat);
}
if ((info.getLineClass() == Clip.class)) {
+ /* check for permission to play audio */
+ AudioPermission perm = new AudioPermission("play", null);
+ perm.checkGuard(null);
+
return new PulseAudioClip(eventLoop, formats, defaultFormat);
}
@@ -365,9 +376,11 @@ public class PulseAudioMixer implements
@Override
public Line[] getSourceLines() {
-
- // FIXME security
-
+
+ /* check for permmission to play audio */
+ AudioPermission perm = new AudioPermission("play", null);
+ perm.checkGuard(null);
+
return (Line[]) sourceLines.toArray(new Line[0]);
}
@@ -392,9 +405,11 @@ public class PulseAudioMixer implements
@Override
public Line[] getTargetLines() {
-
- // FIXME security
-
+
+ /* check for permission to play audio */
+ AudioPermission perm = new AudioPermission("record", null);
+ perm.checkGuard(null);
+
return (Line[]) targetLines.toArray(new TargetDataLine[0]);
}
@@ -477,12 +492,25 @@ public class PulseAudioMixer implements
@Override
synchronized public void close() {
+ /*
+ * only allow the mixer to be controlled if either playback or recording
+ * is allowed
+ */
+
+ try {
+ /* check for permission to play audio */
+ AudioPermission perm = new AudioPermission("play", null);
+ perm.checkGuard(null);
+ } catch (SecurityException e) {
+ /* check for permission to record audio */
+ AudioPermission perm = new AudioPermission("record", null);
+ perm.checkGuard(null);
+ }
+
if (!this.isOpen) {
throw new IllegalStateException("Mixer is not open; cant close");
}
- // FIXME security
-
eventLoopThread.interrupt();
try {
@@ -573,12 +601,25 @@ public class PulseAudioMixer implements
synchronized public void openRemote(String appName, String host,
Integer port) throws UnknownHostException, LineUnavailableException {
+ /*
+ * only allow the mixer to be controlled if either playback or recording
+ * is allowed
+ */
+
+ try {
+ /* check for permission to play audio */
+ AudioPermission perm = new AudioPermission("play", null);
+ perm.checkGuard(null);
+ } catch (SecurityException e) {
+ /* check for permission to record audio */
+ AudioPermission perm = new AudioPermission("record", null);
+ perm.checkGuard(null);
+ }
+
if (isOpen) {
throw new IllegalStateException("Mixer is already open");
}
- // FIXME security
-
InetAddress addr = InetAddress.getAllByName(host)[0];
if (port != null) {
diff -r d4676ea1be88 -r 63fe20298326 src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java Thu Oct 09 17:28:36 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java Fri Oct 10 11:10:27 2008 -0400
@@ -83,12 +83,8 @@ public abstract class PulseAudioPort ext
*
* close = no sound. open = sound
*
- * so we set it to be open by default
*/
-
-
- // TODO what to do if a security exception is thrown?
- open();
+ // FIXME open();
// System.out.println("Opened Target Port " + name);
}
@@ -133,9 +129,7 @@ public abstract class PulseAudioPort ext
@Override
public void close() {
-
- // FIXME security
-
+
native_setVolume((float) 0);
isOpen = false;
fireLineEvent(new LineEvent(this, LineEvent.Type.CLOSE,
@@ -147,9 +141,7 @@ public abstract class PulseAudioPort ext
@Override
public void open() {
-
- // FIXME security
-
+
native_setVolume(volume);
isOpen = true;
fireLineEvent(new LineEvent(this, LineEvent.Type.OPEN,
diff -r d4676ea1be88 -r 63fe20298326 src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Thu Oct 09 17:28:36 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Fri Oct 10 11:10:27 2008 -0400
@@ -40,6 +40,7 @@ import java.util.ArrayList;
import java.util.ArrayList;
import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioPermission;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
@@ -67,7 +68,9 @@ public class PulseAudioSourceDataLine ex
synchronized public void open(AudioFormat format, int bufferSize)
throws LineUnavailableException {
- // FIXME security
+ /* check for permmission to play audio */
+ AudioPermission perm = new AudioPermission("play", null);
+ perm.checkGuard(null);
super.open(format, bufferSize);
@@ -310,11 +313,14 @@ public class PulseAudioSourceDataLine ex
@Override
synchronized public void close() {
+
+ /* check for permmission to play audio */
+ AudioPermission perm = new AudioPermission("play", null);
+ perm.checkGuard(null);
+
if (!isOpen) {
throw new IllegalStateException("not open so cant close");
}
-
- // FIXME security
writeInterrupted = true;
diff -r d4676ea1be88 -r 63fe20298326 src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java Thu Oct 09 17:28:36 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java Fri Oct 10 11:10:27 2008 -0400
@@ -37,6 +37,7 @@ exception statement from your version.
package org.classpath.icedtea.pulseaudio;
+import javax.sound.sampled.AudioPermission;
import javax.sound.sampled.Port;
public class PulseAudioSourcePort extends PulseAudioPort {
@@ -53,7 +54,9 @@ public class PulseAudioSourcePort extend
public void open() {
-
+ /* check for permission to record audio */
+ AudioPermission perm = new AudioPermission("record", null);
+ perm.checkGuard(null);
super.open();
@@ -62,6 +65,14 @@ public class PulseAudioSourcePort extend
}
public void close() {
+
+ /* check for permission to record audio */
+ AudioPermission perm = new AudioPermission("record", null);
+ perm.checkGuard(null);
+
+ if (!isOpen) {
+ throw new IllegalStateException("Port is not open; so cant close");
+ }
PulseAudioMixer parent = PulseAudioMixer.getInstance();
parent.removeSourceLine(this);
diff -r d4676ea1be88 -r 63fe20298326 src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Thu Oct 09 17:28:36 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Fri Oct 10 11:10:27 2008 -0400
@@ -38,6 +38,7 @@ package org.classpath.icedtea.pulseaudio
package org.classpath.icedtea.pulseaudio;
import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioPermission;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.TargetDataLine;
@@ -70,13 +71,15 @@ public class PulseAudioTargetDataLine ex
@Override
synchronized public void close() {
+ /* check for permission to record audio */
+ AudioPermission perm = new AudioPermission("record", null);
+ perm.checkGuard(null);
+
if (!isOpen) {
throw new IllegalStateException(
"Line cant be closed if it isnt open");
}
- // FIXME security
-
PulseAudioMixer parentMixer = PulseAudioMixer.getInstance();
parentMixer.removeTargetLine(this);
@@ -86,12 +89,13 @@ public class PulseAudioTargetDataLine ex
@Override
synchronized public void open(AudioFormat format, int bufferSize)
throws LineUnavailableException {
+ /* check for permission to record audio */
+ AudioPermission perm = new AudioPermission("record", null);
+ perm.checkGuard(null);
+
if (isOpen) {
throw new IllegalStateException("already open");
}
-
- // FIXME security
-
super.open(format, bufferSize);
/* initialize all the member variables */
@@ -223,7 +227,7 @@ public class PulseAudioTargetDataLine ex
/* read a fragment, and drop it from the server */
currentFragment = stream.peek();
-
+
stream.drop();
if (currentFragment == null) {
System.out
diff -r d4676ea1be88 -r 63fe20298326 src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java Thu Oct 09 17:28:36 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java Fri Oct 10 11:10:27 2008 -0400
@@ -37,42 +37,51 @@ exception statement from your version.
package org.classpath.icedtea.pulseaudio;
+import javax.sound.sampled.AudioPermission;
import javax.sound.sampled.Port;
public class PulseAudioTargetPort extends PulseAudioPort {
/* aka speaker */
-
+
static {
System.loadLibrary("pulse-java");
}
public PulseAudioTargetPort(String name, EventLoop eventLoop) {
-
+
super(name, eventLoop);
-
+
}
public void open() {
-
- // FIXME security
-
+
+ /* check for permission to play audio */
+ AudioPermission perm = new AudioPermission("play", null);
+ perm.checkGuard(null);
+
super.open();
-
+
PulseAudioMixer parent = PulseAudioMixer.getInstance();
parent.addTargetLine(this);
}
-
+
public void close() {
+
+ /* check for permission to play audio */
+ AudioPermission perm = new AudioPermission("play", null);
+ perm.checkGuard(null);
- // FIXME
+ if (!isOpen) {
+ throw new IllegalStateException("not open, so cant close Port");
+ }
PulseAudioMixer parent = PulseAudioMixer.getInstance();
parent.removeTargetLine(this);
-
- super.close();
+
+ super.close();
}
-
+
public native byte[] native_setVolume(float newValue);
public synchronized native byte[] native_updateVolumeInfo();
diff -r d4676ea1be88 -r 63fe20298326 unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourcePortTest.java
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourcePortTest.java Thu Oct 09 17:28:36 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourcePortTest.java Fri Oct 10 11:10:27 2008 -0400
@@ -97,6 +97,9 @@ public class PulseAudioSourcePortTest {
if (info.getLineClass() == Port.class) {
System.out.println(info.toString());
Port port = (Port) mixer.getLine(info);
+ if (!port.isOpen()) {
+ port.open();
+ }
FloatControl volumeControl = (FloatControl) port
.getControl(FloatControl.Type.VOLUME);
volumeControl.setValue(60000);
@@ -104,6 +107,7 @@ public class PulseAudioSourcePortTest {
.getControl(BooleanControl.Type.MUTE);
muteControl.setValue(true);
muteControl.setValue(false);
+ port.close();
}
}
}
diff -r d4676ea1be88 -r 63fe20298326 unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetPortTest.java
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetPortTest.java Thu Oct 09 17:28:36 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetPortTest.java Fri Oct 10 11:10:27 2008 -0400
@@ -97,6 +97,9 @@ public class PulseAudioTargetPortTest {
if (info.getLineClass() == Port.class) {
System.out.println(info.toString());
Port port = (Port) mixer.getLine(info);
+ if (!port.isOpen()) {
+ port.open();
+ }
FloatControl volumeControl = (FloatControl) port
More information about the distro-pkg-dev
mailing list