summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2010-11-19 10:58:47 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-11-19 10:58:47 -0800
commit76151f250539586ae6aadf956b949894467b785f (patch)
treeac7827fcd3093b0b8895210f410f5442c1d19202 /media
parent6e050f79f8b9e7ebf9d4802a7c915fc1cffd40e4 (diff)
parent929b3da2fcf061219a82dcced85ffa186c742cc4 (diff)
downloadframeworks_base-76151f250539586ae6aadf956b949894467b785f.zip
frameworks_base-76151f250539586ae6aadf956b949894467b785f.tar.gz
frameworks_base-76151f250539586ae6aadf956b949894467b785f.tar.bz2
Merge "PTP: Fix permissions problems with files imported via PTP"
Diffstat (limited to 'media')
-rw-r--r--media/jni/android_media_MtpClient.cpp3
-rw-r--r--media/mtp/MtpDevice.cpp8
-rw-r--r--media/mtp/MtpDevice.h6
3 files changed, 13 insertions, 4 deletions
diff --git a/media/jni/android_media_MtpClient.cpp b/media/jni/android_media_MtpClient.cpp
index 6235fc0..144dfc8 100644
--- a/media/jni/android_media_MtpClient.cpp
+++ b/media/jni/android_media_MtpClient.cpp
@@ -26,6 +26,7 @@
#include "jni.h"
#include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h"
+#include "private/android_filesystem_config.h"
#include "MtpClient.h"
#include "MtpDevice.h"
@@ -197,7 +198,7 @@ android_media_MtpClient_import_file(JNIEnv *env, jobject thiz,
MtpDevice* device = client->getDevice(device_id);
if (device) {
const char *destPathStr = env->GetStringUTFChars(dest_path, NULL);
- bool result = device->readObject(object_id, destPathStr);
+ bool result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664);
env->ReleaseStringUTFChars(dest_path, destPathStr);
return result;
}
diff --git a/media/mtp/MtpDevice.cpp b/media/mtp/MtpDevice.cpp
index 1b23a8e..416ebfe 100644
--- a/media/mtp/MtpDevice.cpp
+++ b/media/mtp/MtpDevice.cpp
@@ -349,7 +349,7 @@ MtpProperty* MtpDevice::getDevicePropDesc(MtpDeviceProperty code) {
}
// reads the object's data and writes it to the specified file path
-bool MtpDevice::readObject(MtpObjectHandle handle, const char* destPath) {
+bool MtpDevice::readObject(MtpObjectHandle handle, const char* destPath, int group, int perm) {
LOGD("readObject: %s", destPath);
int fd = ::open(destPath, O_RDWR | O_CREAT | O_TRUNC);
if (fd < 0) {
@@ -357,6 +357,12 @@ bool MtpDevice::readObject(MtpObjectHandle handle, const char* destPath) {
return false;
}
+ fchown(fd, getuid(), group);
+ // set permissions
+ int mask = umask(0);
+ fchmod(fd, perm);
+ umask(mask);
+
Mutex::Autolock autoLock(mMutex);
bool result = false;
diff --git a/media/mtp/MtpDevice.h b/media/mtp/MtpDevice.h
index 720502c..21c85d5 100644
--- a/media/mtp/MtpDevice.h
+++ b/media/mtp/MtpDevice.h
@@ -75,7 +75,8 @@ public:
MtpDeviceInfo* getDeviceInfo();
MtpStorageIDList* getStorageIDs();
MtpStorageInfo* getStorageInfo(MtpStorageID storageID);
- MtpObjectHandleList* getObjectHandles(MtpStorageID storageID, MtpObjectFormat format, MtpObjectHandle parent);
+ MtpObjectHandleList* getObjectHandles(MtpStorageID storageID, MtpObjectFormat format,
+ MtpObjectHandle parent);
MtpObjectInfo* getObjectInfo(MtpObjectHandle handle);
void* getThumbnail(MtpObjectHandle handle, int& outLength);
MtpObjectHandle sendObjectInfo(MtpObjectInfo* info);
@@ -86,7 +87,8 @@ public:
MtpProperty* getDevicePropDesc(MtpDeviceProperty code);
- bool readObject(MtpObjectHandle handle, const char* destPath);
+ bool readObject(MtpObjectHandle handle, const char* destPath, int group,
+ int perm);
private:
bool sendRequest(MtpOperationCode operation);