Merge changes Ic0e611f5,Ic06d754e

* changes:
  MTP: Remove retry loop from MTP server code
  MTP: Compatibility fixes for transferring strings
This commit is contained in:
Mike Lockwood
2010-08-18 11:50:49 -07:00
committed by Android (Google) Code Review
4 changed files with 26 additions and 41 deletions

View File

@@ -55,7 +55,6 @@ private:
MtpDatabase* mDatabase;
MtpServer* mServer;
String8 mStoragePath;
bool mDone;
jobject mJavaServer;
public:
@@ -63,41 +62,31 @@ public:
: mDatabase(database),
mServer(NULL),
mStoragePath(storagePath),
mDone(false),
mJavaServer(javaServer)
{
}
virtual bool threadLoop() {
while (1) {
int fd = open("/dev/mtp_usb", O_RDWR);
printf("open returned %d\n", fd);
if (fd < 0) {
LOGE("could not open MTP driver\n");
break;
}
sMutex.lock();
mServer = new MtpServer(fd, mDatabase, AID_SDCARD_RW, 0664, 0775);
mServer->addStorage(mStoragePath);
sMutex.unlock();
LOGD("MtpThread mServer->run");
mServer->run();
close(fd);
sMutex.lock();
delete mServer;
mServer = NULL;
if (mDone)
goto done;
sMutex.unlock();
// wait a bit before retrying
sleep(1);
int fd = open("/dev/mtp_usb", O_RDWR);
printf("open returned %d\n", fd);
if (fd < 0) {
LOGE("could not open MTP driver\n");
return false;
}
sMutex.lock();
done:
mServer = new MtpServer(fd, mDatabase, AID_SDCARD_RW, 0664, 0775);
mServer->addStorage(mStoragePath);
sMutex.unlock();
LOGD("MtpThread mServer->run");
mServer->run();
close(fd);
sMutex.lock();
delete mServer;
mServer = NULL;
JNIEnv* env = AndroidRuntime::getJNIEnv();
env->SetIntField(mJavaServer, field_context, 0);
env->DeleteGlobalRef(mJavaServer);
@@ -107,11 +96,6 @@ done:
return false;
}
void setDone() {
LOGD("setDone");
mDone = true;
}
void sendObjectAdded(MtpObjectHandle handle) {
sMutex.lock();
if (mServer)
@@ -171,11 +155,6 @@ android_media_MtpServer_stop(JNIEnv *env, jobject thiz)
{
#ifdef HAVE_ANDROID_OS
LOGD("stop\n");
sMutex.lock();
MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context);
if (thread)
thread->setDone();
sMutex.unlock();
#endif
}

View File

@@ -325,9 +325,12 @@ void MtpDataPacket::putString(const uint16_t* string) {
else
break;
}
putUInt8(count);
putUInt8(count > 0 ? count + 1 : 0);
for (int i = 0; i < count; i++)
putUInt16(string[i]);
// only terminate with zero if string is not empty
if (count > 0)
putUInt16(0);
}
#ifdef MTP_DEVICE

View File

@@ -83,7 +83,7 @@ public:
void putString(const MtpStringBuffer& string);
void putString(const char* string);
void putString(const uint16_t* string);
inline void putEmptyString() { putUInt16(0); }
inline void putEmptyString() { putUInt8(0); }
inline void putEmptyArray() { putUInt32(0); }

View File

@@ -112,7 +112,7 @@ void MtpStringBuffer::readFromPacket(MtpDataPacket* packet) {
void MtpStringBuffer::writeToPacket(MtpDataPacket* packet) const {
int count = mCharCount;
const uint8_t* src = mBuffer;
packet->putUInt8(count);
packet->putUInt8(count > 0 ? count + 1 : 0);
// expand utf8 to 16 bit chars
for (int i = 0; i < count; i++) {
@@ -133,6 +133,9 @@ void MtpStringBuffer::writeToPacket(MtpDataPacket* packet) const {
}
packet->putUInt16(ch);
}
// only terminate with zero if string is not empty
if (count > 0)
packet->putUInt16(0);
}
} // namespace android