Skip to content

Commit fc301b0

Browse files
author
Dave Burke
committed
Require INTERNET permission for network-based content.
Bug #1870981 Change-Id: Ia3ad166390c4d60cea19c3783895b078a2c4c15f
1 parent 117999d commit fc301b0

File tree

12 files changed

+155
-190
lines changed

12 files changed

+155
-190
lines changed

api/current.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10668,7 +10668,7 @@ package android.media {
1066810668
method public void setAuxEffectSendLevel(float);
1066910669
method public void setDataSource(android.content.Context, android.net.Uri) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
1067010670
method public void setDataSource(android.content.Context, android.net.Uri, java.util.Map<java.lang.String, java.lang.String>) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
10671-
method public void setDataSource(java.lang.String) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException;
10671+
method public void setDataSource(java.lang.String) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
1067210672
method public void setDataSource(java.io.FileDescriptor) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException;
1067310673
method public void setDataSource(java.io.FileDescriptor, long, long) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException;
1067410674
method public void setDisplay(android.view.SurfaceHolder);

cmds/stagefright/stream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ int main(int argc, char **argv) {
357357
}
358358

359359
sp<IMediaPlayer> player =
360-
service->create(getpid(), client, source, 0);
360+
service->create(getpid(), client, 0);
361361

362-
if (player != NULL) {
362+
if (player != NULL && player->setDataSource(source) == NO_ERROR) {
363363
player->setVideoSurface(surface);
364364
player->start();
365365

include/media/IMediaPlayer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
#include <utils/RefBase.h>
2121
#include <binder/IInterface.h>
2222
#include <binder/Parcel.h>
23+
#include <utils/KeyedVector.h>
2324

2425
namespace android {
2526

2627
class Parcel;
2728
class Surface;
29+
class IStreamSource;
2830
class ISurfaceTexture;
2931

3032
class IMediaPlayer: public IInterface
@@ -34,6 +36,10 @@ class IMediaPlayer: public IInterface
3436

3537
virtual void disconnect() = 0;
3638

39+
virtual status_t setDataSource(const char *url,
40+
const KeyedVector<String8, String8>* headers) = 0;
41+
virtual status_t setDataSource(int fd, int64_t offset, int64_t length) = 0;
42+
virtual status_t setDataSource(const sp<IStreamSource>& source) = 0;
3743
virtual status_t setVideoSurface(const sp<Surface>& surface) = 0;
3844
virtual status_t setVideoSurfaceTexture(
3945
const sp<ISurfaceTexture>& surfaceTexture) = 0;

include/media/IMediaPlayerService.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,9 @@ class IMediaPlayerService: public IInterface
3939
public:
4040
DECLARE_META_INTERFACE(MediaPlayerService);
4141

42-
virtual sp<IMediaRecorder> createMediaRecorder(pid_t pid) = 0;
42+
virtual sp<IMediaRecorder> createMediaRecorder(pid_t pid) = 0;
4343
virtual sp<IMediaMetadataRetriever> createMetadataRetriever(pid_t pid) = 0;
44-
virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client,
45-
const char* url, const KeyedVector<String8, String8> *headers = NULL,
46-
int audioSessionId = 0) = 0;
47-
virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client,
48-
int fd, int64_t offset, int64_t length, int audioSessionId) = 0;
49-
50-
virtual sp<IMediaPlayer> create(
51-
pid_t pid, const sp<IMediaPlayerClient> &client,
52-
const sp<IStreamSource> &source, int audioSessionId) = 0;
44+
virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client, int audioSessionId = 0) = 0;
5345

5446
virtual sp<IMemory> decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat) = 0;
5547
virtual sp<IMemory> decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat) = 0;

include/media/mediaplayer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <media/IMediaPlayerClient.h>
2222
#include <media/IMediaPlayer.h>
2323
#include <media/IMediaDeathNotifier.h>
24+
#include <media/IStreamSource.h>
2425

2526
#include <utils/KeyedVector.h>
2627
#include <utils/String8.h>
@@ -168,6 +169,7 @@ class MediaPlayer : public BnMediaPlayerClient,
168169
const KeyedVector<String8, String8> *headers);
169170

170171
status_t setDataSource(int fd, int64_t offset, int64_t length);
172+
status_t setDataSource(const sp<IStreamSource> &source);
171173
status_t setVideoSurface(const sp<Surface>& surface);
172174
status_t setVideoSurfaceTexture(
173175
const sp<ISurfaceTexture>& surfaceTexture);
@@ -206,7 +208,7 @@ class MediaPlayer : public BnMediaPlayerClient,
206208
status_t seekTo_l(int msec);
207209
status_t prepareAsync_l();
208210
status_t getDuration_l(int *msec);
209-
status_t setDataSource(const sp<IMediaPlayer>& player);
211+
status_t attachNewPlayer(const sp<IMediaPlayer>& player);
210212
void disconnectNativeWindow();
211213
status_t reset_l();
212214

media/java/android/media/MediaPlayer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@
459459
* android.R.styleable#AndroidManifestUsesPermission &lt;uses-permission&gt;}
460460
* element.
461461
*
462+
* <p>This class requires the {@link android.Manifest.permission#INTERNET} permission
463+
* when used with network-based content.
464+
*
462465
* <a name="Callbacks"></a>
463466
* <h3>Callbacks</h3>
464467
* <p>Applications may want to register for informational and error
@@ -828,6 +831,7 @@ public void setDataSource(Context context, Uri uri, Map<String, String> headers)
828831
fd.close();
829832
}
830833
}
834+
831835
Log.d(TAG, "Couldn't open file on client side, trying server side");
832836
setDataSource(uri.toString(), headers);
833837
return;
@@ -839,7 +843,8 @@ public void setDataSource(Context context, Uri uri, Map<String, String> headers)
839843
* @param path the path of the file, or the http/rtsp URL of the stream you want to play
840844
* @throws IllegalStateException if it is called in an invalid state
841845
*/
842-
public native void setDataSource(String path) throws IOException, IllegalArgumentException, IllegalStateException;
846+
public native void setDataSource(String path)
847+
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;
843848

844849
/**
845850
* Sets the data source (file-path or http/rtsp URL) to use.
@@ -850,7 +855,7 @@ public void setDataSource(Context context, Uri uri, Map<String, String> headers)
850855
* @hide pending API council
851856
*/
852857
public void setDataSource(String path, Map<String, String> headers)
853-
throws IOException, IllegalArgumentException, IllegalStateException
858+
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException
854859
{
855860
String[] keys = null;
856861
String[] values = null;
@@ -871,7 +876,7 @@ public void setDataSource(String path, Map<String, String> headers)
871876

872877
private native void _setDataSource(
873878
String path, String[] keys, String[] values)
874-
throws IOException, IllegalArgumentException, IllegalStateException;
879+
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;
875880

876881
/**
877882
* Sets the data source (FileDescriptor) to use. It is the caller's responsibility

media/jni/android_media_MediaPlayer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ static void process_media_player_call(JNIEnv *env, jobject thiz, status_t opStat
155155
} else { // Throw exception!
156156
if ( opStatus == (status_t) INVALID_OPERATION ) {
157157
jniThrowException(env, "java/lang/IllegalStateException", NULL);
158+
} else if ( opStatus == (status_t) PERMISSION_DENIED ) {
159+
jniThrowException(env, "java/lang/SecurityException", NULL);
158160
} else if ( opStatus != (status_t) OK ) {
159161
if (strlen(message) > 230) {
160162
// if the message is too long, don't bother displaying the status code

media/libmedia/IMediaPlayer.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@
2121
#include <binder/Parcel.h>
2222

2323
#include <media/IMediaPlayer.h>
24+
#include <media/IStreamSource.h>
25+
2426
#include <surfaceflinger/ISurface.h>
2527
#include <surfaceflinger/Surface.h>
2628
#include <gui/ISurfaceTexture.h>
29+
#include <utils/String8.h>
2730

2831
namespace android {
2932

3033
enum {
3134
DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
35+
SET_DATA_SOURCE_URL,
36+
SET_DATA_SOURCE_FD,
37+
SET_DATA_SOURCE_STREAM,
3238
SET_VIDEO_SURFACE,
3339
PREPARE_ASYNC,
3440
START,
@@ -68,6 +74,43 @@ class BpMediaPlayer: public BpInterface<IMediaPlayer>
6874
remote()->transact(DISCONNECT, data, &reply);
6975
}
7076

77+
status_t setDataSource(const char* url,
78+
const KeyedVector<String8, String8>* headers)
79+
{
80+
Parcel data, reply;
81+
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
82+
data.writeCString(url);
83+
if (headers == NULL) {
84+
data.writeInt32(0);
85+
} else {
86+
// serialize the headers
87+
data.writeInt32(headers->size());
88+
for (size_t i = 0; i < headers->size(); ++i) {
89+
data.writeString8(headers->keyAt(i));
90+
data.writeString8(headers->valueAt(i));
91+
}
92+
}
93+
remote()->transact(SET_DATA_SOURCE_URL, data, &reply);
94+
return reply.readInt32();
95+
}
96+
97+
status_t setDataSource(int fd, int64_t offset, int64_t length) {
98+
Parcel data, reply;
99+
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
100+
data.writeFileDescriptor(fd);
101+
data.writeInt64(offset);
102+
data.writeInt64(length);
103+
remote()->transact(SET_DATA_SOURCE_FD, data, &reply);
104+
return reply.readInt32();
105+
}
106+
107+
status_t setDataSource(const sp<IStreamSource> &source) {
108+
Parcel data, reply;
109+
data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
110+
data.writeStrongBinder(source->asBinder());
111+
return reply.readInt32();
112+
}
113+
71114
// pass the buffered Surface to the media player service
72115
status_t setVideoSurface(const sp<Surface>& surface)
73116
{
@@ -273,6 +316,34 @@ status_t BnMediaPlayer::onTransact(
273316
disconnect();
274317
return NO_ERROR;
275318
} break;
319+
case SET_DATA_SOURCE_URL: {
320+
CHECK_INTERFACE(IMediaPlayer, data, reply);
321+
const char* url = data.readCString();
322+
KeyedVector<String8, String8> headers;
323+
int32_t numHeaders = data.readInt32();
324+
for (int i = 0; i < numHeaders; ++i) {
325+
String8 key = data.readString8();
326+
String8 value = data.readString8();
327+
headers.add(key, value);
328+
}
329+
reply->writeInt32(setDataSource(url, numHeaders > 0 ? &headers : NULL));
330+
return NO_ERROR;
331+
} break;
332+
case SET_DATA_SOURCE_FD: {
333+
CHECK_INTERFACE(IMediaPlayer, data, reply);
334+
int fd = data.readFileDescriptor();
335+
int64_t offset = data.readInt64();
336+
int64_t length = data.readInt64();
337+
reply->writeInt32(setDataSource(fd, offset, length));
338+
return NO_ERROR;
339+
}
340+
case SET_DATA_SOURCE_STREAM: {
341+
CHECK_INTERFACE(IMediaPlayer, data, reply);
342+
sp<IStreamSource> source =
343+
interface_cast<IStreamSource>(data.readStrongBinder());
344+
reply->writeInt32(setDataSource(source));
345+
return NO_ERROR;
346+
}
276347
case SET_VIDEO_SURFACE: {
277348
CHECK_INTERFACE(IMediaPlayer, data, reply);
278349
sp<Surface> surface = Surface::readFromParcel(data);

media/libmedia/IMediaPlayerService.cpp

Lines changed: 5 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
namespace android {
3131

3232
enum {
33-
CREATE_URL = IBinder::FIRST_CALL_TRANSACTION,
34-
CREATE_FD,
35-
CREATE_STREAM,
33+
CREATE = IBinder::FIRST_CALL_TRANSACTION,
3634
DECODE_URL,
3735
DECODE_FD,
3836
CREATE_MEDIA_RECORDER,
@@ -60,28 +58,14 @@ class BpMediaPlayerService: public BpInterface<IMediaPlayerService>
6058
}
6159

6260
virtual sp<IMediaPlayer> create(
63-
pid_t pid, const sp<IMediaPlayerClient>& client,
64-
const char* url, const KeyedVector<String8, String8> *headers, int audioSessionId) {
61+
pid_t pid, const sp<IMediaPlayerClient>& client, int audioSessionId) {
6562
Parcel data, reply;
6663
data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
6764
data.writeInt32(pid);
6865
data.writeStrongBinder(client->asBinder());
69-
data.writeCString(url);
70-
71-
if (headers == NULL) {
72-
data.writeInt32(0);
73-
} else {
74-
// serialize the headers
75-
data.writeInt32(headers->size());
76-
for (size_t i = 0; i < headers->size(); ++i) {
77-
data.writeString8(headers->keyAt(i));
78-
data.writeString8(headers->valueAt(i));
79-
}
80-
}
8166
data.writeInt32(audioSessionId);
8267

83-
remote()->transact(CREATE_URL, data, &reply);
84-
68+
remote()->transact(CREATE, data, &reply);
8569
return interface_cast<IMediaPlayer>(reply.readStrongBinder());
8670
}
8771

@@ -94,38 +78,6 @@ class BpMediaPlayerService: public BpInterface<IMediaPlayerService>
9478
return interface_cast<IMediaRecorder>(reply.readStrongBinder());
9579
}
9680

97-
virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client, int fd,
98-
int64_t offset, int64_t length, int audioSessionId)
99-
{
100-
Parcel data, reply;
101-
data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
102-
data.writeInt32(pid);
103-
data.writeStrongBinder(client->asBinder());
104-
data.writeFileDescriptor(fd);
105-
data.writeInt64(offset);
106-
data.writeInt64(length);
107-
data.writeInt32(audioSessionId);
108-
109-
remote()->transact(CREATE_FD, data, &reply);
110-
111-
return interface_cast<IMediaPlayer>(reply.readStrongBinder());;
112-
}
113-
114-
virtual sp<IMediaPlayer> create(
115-
pid_t pid, const sp<IMediaPlayerClient> &client,
116-
const sp<IStreamSource> &source, int audioSessionId) {
117-
Parcel data, reply;
118-
data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
119-
data.writeInt32(static_cast<int32_t>(pid));
120-
data.writeStrongBinder(client->asBinder());
121-
data.writeStrongBinder(source->asBinder());
122-
data.writeInt32(static_cast<int32_t>(audioSessionId));
123-
124-
remote()->transact(CREATE_STREAM, data, &reply);
125-
126-
return interface_cast<IMediaPlayer>(reply.readStrongBinder());;
127-
}
128-
12981
virtual sp<IMemory> decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat)
13082
{
13183
Parcel data, reply;
@@ -181,62 +133,16 @@ status_t BnMediaPlayerService::onTransact(
181133
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
182134
{
183135
switch(code) {
184-
case CREATE_URL: {
136+
case CREATE: {
185137
CHECK_INTERFACE(IMediaPlayerService, data, reply);
186138
pid_t pid = data.readInt32();
187139
sp<IMediaPlayerClient> client =
188140
interface_cast<IMediaPlayerClient>(data.readStrongBinder());
189-
const char* url = data.readCString();
190-
191-
KeyedVector<String8, String8> headers;
192-
int32_t numHeaders = data.readInt32();
193-
for (int i = 0; i < numHeaders; ++i) {
194-
String8 key = data.readString8();
195-
String8 value = data.readString8();
196-
headers.add(key, value);
197-
}
198-
int audioSessionId = data.readInt32();
199-
200-
sp<IMediaPlayer> player = create(
201-
pid, client, url, numHeaders > 0 ? &headers : NULL, audioSessionId);
202-
203-
reply->writeStrongBinder(player->asBinder());
204-
return NO_ERROR;
205-
} break;
206-
case CREATE_FD: {
207-
CHECK_INTERFACE(IMediaPlayerService, data, reply);
208-
pid_t pid = data.readInt32();
209-
sp<IMediaPlayerClient> client = interface_cast<IMediaPlayerClient>(data.readStrongBinder());
210-
int fd = dup(data.readFileDescriptor());
211-
int64_t offset = data.readInt64();
212-
int64_t length = data.readInt64();
213141
int audioSessionId = data.readInt32();
214-
215-
sp<IMediaPlayer> player = create(pid, client, fd, offset, length, audioSessionId);
142+
sp<IMediaPlayer> player = create(pid, client, audioSessionId);
216143
reply->writeStrongBinder(player->asBinder());
217144
return NO_ERROR;
218145
} break;
219-
case CREATE_STREAM:
220-
{
221-
CHECK_INTERFACE(IMediaPlayerService, data, reply);
222-
223-
pid_t pid = static_cast<pid_t>(data.readInt32());
224-
225-
sp<IMediaPlayerClient> client =
226-
interface_cast<IMediaPlayerClient>(data.readStrongBinder());
227-
228-
sp<IStreamSource> source =
229-
interface_cast<IStreamSource>(data.readStrongBinder());
230-
231-
int audioSessionId = static_cast<int>(data.readInt32());
232-
233-
sp<IMediaPlayer> player =
234-
create(pid, client, source, audioSessionId);
235-
236-
reply->writeStrongBinder(player->asBinder());
237-
return OK;
238-
break;
239-
}
240146
case DECODE_URL: {
241147
CHECK_INTERFACE(IMediaPlayerService, data, reply);
242148
const char* url = data.readCString();

0 commit comments

Comments
 (0)