Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9823d203 authored by Mike Lockwood's avatar Mike Lockwood Committed by Android (Google) Code Review
Browse files

Merge "MTP: replace printfs with logcat"

parents 2658cf47 3e6616dd
Loading
Loading
Loading
Loading
+4 −5
Original line number Original line Diff line number Diff line
@@ -15,7 +15,10 @@
 */
 */


#define LOG_TAG "MtpClient"
#define LOG_TAG "MtpClient"
#include "utils/Log.h"

#include "MtpDebug.h"
#include "MtpClient.h"
#include "MtpDevice.h"


#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
@@ -33,10 +36,6 @@
#include <linux/usb_ch9.h>
#include <linux/usb_ch9.h>
#endif
#endif


#include "MtpClient.h"
#include "MtpDevice.h"
#include "MtpDebug.h"

namespace android {
namespace android {


MtpClient::MtpClient()
MtpClient::MtpClient()
+2 −1
Original line number Original line Diff line number Diff line
@@ -15,8 +15,8 @@
 */
 */


#define LOG_TAG "MtpCursor"
#define LOG_TAG "MtpCursor"
#include "utils/Log.h"


#include "MtpDebug.h"
#include "MtpClient.h"
#include "MtpClient.h"
#include "MtpCursor.h"
#include "MtpCursor.h"
#include "MtpDevice.h"
#include "MtpDevice.h"
@@ -24,6 +24,7 @@
#include "MtpObjectInfo.h"
#include "MtpObjectInfo.h"
#include "MtpStorageInfo.h"
#include "MtpStorageInfo.h"



#include "binder/CursorWindow.h"
#include "binder/CursorWindow.h"


namespace android {
namespace android {
+2 −3
Original line number Original line Diff line number Diff line
@@ -14,6 +14,8 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#define LOG_TAG "MtpDataPacket"

#include <stdio.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/types.h>
#include <fcntl.h>
#include <fcntl.h>
@@ -312,15 +314,12 @@ void MtpDataPacket::putString(const char* s)
int MtpDataPacket::read(int fd) {
int MtpDataPacket::read(int fd) {
    // first read the header
    // first read the header
    int ret = ::read(fd, mBuffer, MTP_CONTAINER_HEADER_SIZE);
    int ret = ::read(fd, mBuffer, MTP_CONTAINER_HEADER_SIZE);
printf("MtpDataPacket::read 1 returned %d\n", ret);
    if (ret != MTP_CONTAINER_HEADER_SIZE)
    if (ret != MTP_CONTAINER_HEADER_SIZE)
        return -1;
        return -1;
    // then the following data
    // then the following data
    int total = MtpPacket::getUInt32(MTP_CONTAINER_LENGTH_OFFSET);
    int total = MtpPacket::getUInt32(MTP_CONTAINER_LENGTH_OFFSET);
    int remaining = total - MTP_CONTAINER_HEADER_SIZE;
    int remaining = total - MTP_CONTAINER_HEADER_SIZE;
printf("total: %d, remaining: %d\n", total, remaining);
    ret = ::read(fd, &mBuffer[0] + MTP_CONTAINER_HEADER_SIZE, remaining);
    ret = ::read(fd, &mBuffer[0] + MTP_CONTAINER_HEADER_SIZE, remaining);
printf("MtpDataPacket::read 2 returned %d\n", ret);
    if (ret != remaining)
    if (ret != remaining)
        return -1;
        return -1;


+20 −17
Original line number Original line Diff line number Diff line
@@ -14,6 +14,9 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#define LOG_TAG "MtpDatabase"

#include "MtpDebug.h"
#include "MtpDatabase.h"
#include "MtpDatabase.h"
#include "MtpDataPacket.h"
#include "MtpDataPacket.h"
#include "MtpUtils.h"
#include "MtpUtils.h"
@@ -140,64 +143,64 @@ bool MtpDatabase::open(const char* path, bool create) {


    // create tables and indices if necessary
    // create tables and indices if necessary
    if (!exec(FILE_TABLE_CREATE)) {
    if (!exec(FILE_TABLE_CREATE)) {
        fprintf(stderr, "could not create file table\n");
        LOGE("could not create file table");
        return false;
        return false;
    }
    }
    if (!exec(PATH_INDEX_CREATE)) {
    if (!exec(PATH_INDEX_CREATE)) {
        fprintf(stderr, "could not path index on file table\n");
        LOGE("could not path index on file table");
        return false;
        return false;
    }
    }
    if (!exec(AUDIO_TABLE_CREATE)) {
    if (!exec(AUDIO_TABLE_CREATE)) {
        fprintf(stderr, "could not create file table\n");
        LOGE("could not create file table");
        return false;
        return false;
    }
    }


    if (!mFileIdQuery) {
    if (!mFileIdQuery) {
        mFileIdQuery = new SqliteStatement(this);
        mFileIdQuery = new SqliteStatement(this);
        if (!mFileIdQuery->prepare(FILE_ID_QUERY)) {
        if (!mFileIdQuery->prepare(FILE_ID_QUERY)) {
            fprintf(stderr, "could not compile FILE_ID_QUERY\n");
            LOGE("could not compile FILE_ID_QUERY");
            exit(-1);
            exit(-1);
        }
        }
    }
    }
    if (!mFilePathQuery) {
    if (!mFilePathQuery) {
        mFilePathQuery = new SqliteStatement(this);
        mFilePathQuery = new SqliteStatement(this);
        if (!mFilePathQuery->prepare(FILE_PATH_QUERY)) {
        if (!mFilePathQuery->prepare(FILE_PATH_QUERY)) {
            fprintf(stderr, "could not compile FILE_PATH_QUERY\n");
            LOGE("could not compile FILE_PATH_QUERY");
            exit(-1);
            exit(-1);
        }
        }
    }
    }
    if (!mObjectInfoQuery) {
    if (!mObjectInfoQuery) {
        mObjectInfoQuery = new SqliteStatement(this);
        mObjectInfoQuery = new SqliteStatement(this);
        if (!mObjectInfoQuery->prepare(GET_OBJECT_INFO_QUERY)) {
        if (!mObjectInfoQuery->prepare(GET_OBJECT_INFO_QUERY)) {
            fprintf(stderr, "could not compile GET_OBJECT_INFO_QUERY\n");
            LOGE("could not compile GET_OBJECT_INFO_QUERY");
            exit(-1);
            exit(-1);
        }
        }
    }
    }
    if (!mFileInserter) {
    if (!mFileInserter) {
        mFileInserter = new SqliteStatement(this);
        mFileInserter = new SqliteStatement(this);
        if (!mFileInserter->prepare(FILE_INSERT)) {
        if (!mFileInserter->prepare(FILE_INSERT)) {
            fprintf(stderr, "could not compile FILE_INSERT\n");
            LOGE("could not compile FILE_INSERT\n");
            exit(-1);
            exit(-1);
        }
        }
    }
    }
    if (!mFileDeleter) {
    if (!mFileDeleter) {
        mFileDeleter = new SqliteStatement(this);
        mFileDeleter = new SqliteStatement(this);
        if (!mFileDeleter->prepare(FILE_DELETE)) {
        if (!mFileDeleter->prepare(FILE_DELETE)) {
            fprintf(stderr, "could not compile FILE_DELETE\n");
            LOGE("could not compile FILE_DELETE\n");
            exit(-1);
            exit(-1);
        }
        }
    }
    }
    if (!mAudioInserter) {
    if (!mAudioInserter) {
        mAudioInserter = new SqliteStatement(this);
        mAudioInserter = new SqliteStatement(this);
        if (!mAudioInserter->prepare(AUDIO_INSERT)) {
        if (!mAudioInserter->prepare(AUDIO_INSERT)) {
            fprintf(stderr, "could not compile AUDIO_INSERT\n");
            LOGE("could not compile AUDIO_INSERT\n");
            exit(-1);
            exit(-1);
        }
        }
    }
    }
    if (!mAudioDeleter) {
    if (!mAudioDeleter) {
        mAudioDeleter = new SqliteStatement(this);
        mAudioDeleter = new SqliteStatement(this);
        if (!mAudioDeleter->prepare(AUDIO_DELETE)) {
        if (!mAudioDeleter->prepare(AUDIO_DELETE)) {
            fprintf(stderr, "could not compile AUDIO_DELETE\n");
            LOGE("could not compile AUDIO_DELETE\n");
            exit(-1);
            exit(-1);
        }
        }
    }
    }
@@ -364,14 +367,14 @@ MtpObjectHandleList* MtpDatabase::getObjectList(MtpStorageID storageID,
    query += ";";
    query += ";";


    SqliteStatement stmt(this);
    SqliteStatement stmt(this);
    printf("%s\n", (const char *)query);
    LOGV("%s", (const char *)query);
    stmt.prepare(query);
    stmt.prepare(query);


    MtpObjectHandleList* list = new MtpObjectHandleList();
    MtpObjectHandleList* list = new MtpObjectHandleList();
    while (!stmt.isDone()) {
    while (!stmt.isDone()) {
        if (stmt.step()) {
        if (stmt.step()) {
            int index = stmt.getColumnInt(0);
            int index = stmt.getColumnInt(0);
            printf("stmt.getColumnInt returned %d\n", index);
            LOGV("stmt.getColumnInt returned %d", index);
            if (index > 0) {
            if (index > 0) {
                MtpObjectFormat format = stmt.getColumnInt(1);
                MtpObjectFormat format = stmt.getColumnInt(1);
                index |= getTableForFile(format);
                index |= getTableForFile(format);
@@ -379,7 +382,7 @@ MtpObjectHandleList* MtpDatabase::getObjectList(MtpStorageID storageID,
            }
            }
        }
        }
    }
    }
    printf("list size: %d\n", list->size());
    LOGV("list size: %d", list->size());
    return list;
    return list;
}
}


@@ -405,7 +408,7 @@ MtpResponseCode MtpDatabase::getObjectProperty(MtpObjectHandle handle,
    query += ";";
    query += ";";


    SqliteStatement stmt(this);
    SqliteStatement stmt(this);
    printf("%s\n", (const char *)query);
    LOGV("%s", (const char *)query);
    stmt.prepare(query);
    stmt.prepare(query);


    if (!stmt.step())
    if (!stmt.step())
@@ -440,7 +443,7 @@ MtpResponseCode MtpDatabase::getObjectProperty(MtpObjectHandle handle,
            packet.putString(stmt.getColumnString(0));
            packet.putString(stmt.getColumnString(0));
            break;
            break;
        default:
        default:
            fprintf(stderr, "unsupported object type\n");
            LOGE("unsupported object type\n");
            return MTP_RESPONSE_INVALID_OBJECT_HANDLE;
            return MTP_RESPONSE_INVALID_OBJECT_HANDLE;
    }
    }
    return MTP_RESPONSE_OK;
    return MTP_RESPONSE_OK;
@@ -472,7 +475,7 @@ MtpResponseCode MtpDatabase::getObjectInfo(MtpObjectHandle handle,
                            MTP_ASSOCIATION_TYPE_GENERIC_FOLDER :
                            MTP_ASSOCIATION_TYPE_GENERIC_FOLDER :
                            MTP_ASSOCIATION_TYPE_UNDEFINED);
                            MTP_ASSOCIATION_TYPE_UNDEFINED);


    printf("storageID: %d, format: %d, parent: %d\n", storageID, format, parent);
    LOGV("storageID: %d, format: %d, parent: %d", storageID, format, parent);


    packet.putUInt32(storageID);
    packet.putUInt32(storageID);
    packet.putUInt16(format);
    packet.putUInt16(format);
@@ -549,7 +552,7 @@ MtpObjectHandle* MtpDatabase::getFileList(int& outCount) {


        for (int i = 0; i < count; i++) {
        for (int i = 0; i < count; i++) {
            if (!stmt2.step()) {
            if (!stmt2.step()) {
                printf("getFileList ended early\n");
                LOGW("getFileList ended early");
                count = i;
                count = i;
                break;
                break;
            }
            }
+3 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,9 @@
#ifndef _MTP_DEBUG_H
#ifndef _MTP_DEBUG_H
#define _MTP_DEBUG_H
#define _MTP_DEBUG_H


#define LOG_NDEBUG 0
#include <utils/Log.h>

#include "MtpTypes.h"
#include "MtpTypes.h"


namespace android {
namespace android {
Loading