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

Commit b6ed343e authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add support for MTP perceived device type property."

parents cb4a3c55 13bb2f4d
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.media.MediaScanner;
import android.net.Uri;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.BatteryManager;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.provider.MediaStore;
import android.provider.MediaStore;
import android.provider.MediaStore.Audio;
import android.provider.MediaStore.Audio;
import android.provider.MediaStore.Files;
import android.provider.MediaStore.Files;
@@ -133,6 +134,8 @@ public class MtpDatabase implements AutoCloseable {
    private int mBatteryLevel;
    private int mBatteryLevel;
    private int mBatteryScale;
    private int mBatteryScale;


    private int mDeviceType;

    static {
    static {
        System.loadLibrary("media_jni");
        System.loadLibrary("media_jni");
    }
    }
@@ -195,6 +198,7 @@ public class MtpDatabase implements AutoCloseable {
        }
        }


        initDeviceProperties(context);
        initDeviceProperties(context);
        mDeviceType = SystemProperties.getInt("sys.usb.mtp.device_type", 0);


        mCloseGuard.open("close");
        mCloseGuard.open("close");
    }
    }
@@ -710,6 +714,7 @@ public class MtpDatabase implements AutoCloseable {
            MtpConstants.DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME,
            MtpConstants.DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME,
            MtpConstants.DEVICE_PROPERTY_IMAGE_SIZE,
            MtpConstants.DEVICE_PROPERTY_IMAGE_SIZE,
            MtpConstants.DEVICE_PROPERTY_BATTERY_LEVEL,
            MtpConstants.DEVICE_PROPERTY_BATTERY_LEVEL,
            MtpConstants.DEVICE_PROPERTY_PERCEIVED_DEVICE_TYPE,
        };
        };
    }
    }


@@ -869,6 +874,10 @@ public class MtpDatabase implements AutoCloseable {
                outStringValue[imageSize.length()] = 0;
                outStringValue[imageSize.length()] = 0;
                return MtpConstants.RESPONSE_OK;
                return MtpConstants.RESPONSE_OK;


            case MtpConstants.DEVICE_PROPERTY_PERCEIVED_DEVICE_TYPE:
                outIntValue[0] = mDeviceType;
                return MtpConstants.RESPONSE_OK;

            // DEVICE_PROPERTY_BATTERY_LEVEL is implemented in the JNI code
            // DEVICE_PROPERTY_BATTERY_LEVEL is implemented in the JNI code


            default:
            default:
+11 −0
Original line number Original line Diff line number Diff line
@@ -76,6 +76,7 @@ static jmethodID method_sessionEnded;
static jfieldID field_context;
static jfieldID field_context;
static jfieldID field_batteryLevel;
static jfieldID field_batteryLevel;
static jfieldID field_batteryScale;
static jfieldID field_batteryScale;
static jfieldID field_deviceType;


// MtpPropertyList fields
// MtpPropertyList fields
static jfieldID field_mCount;
static jfieldID field_mCount;
@@ -1030,6 +1031,7 @@ static const PropertyTableEntry kDevicePropertyTable[] = {
    {   MTP_DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME,       MTP_TYPE_STR },
    {   MTP_DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME,       MTP_TYPE_STR },
    {   MTP_DEVICE_PROPERTY_IMAGE_SIZE,                 MTP_TYPE_STR },
    {   MTP_DEVICE_PROPERTY_IMAGE_SIZE,                 MTP_TYPE_STR },
    {   MTP_DEVICE_PROPERTY_BATTERY_LEVEL,              MTP_TYPE_UINT8 },
    {   MTP_DEVICE_PROPERTY_BATTERY_LEVEL,              MTP_TYPE_UINT8 },
    {   MTP_DEVICE_PROPERTY_PERCEIVED_DEVICE_TYPE,      MTP_TYPE_UINT32 },
};
};


bool MyMtpDatabase::getObjectPropertyInfo(MtpObjectProperty property, int& type) {
bool MyMtpDatabase::getObjectPropertyInfo(MtpObjectProperty property, int& type) {
@@ -1209,6 +1211,10 @@ MtpProperty* MyMtpDatabase::getDevicePropertyDesc(MtpDeviceProperty property) {
            result->setFormRange(0, env->GetIntField(mDatabase, field_batteryScale), 1);
            result->setFormRange(0, env->GetIntField(mDatabase, field_batteryScale), 1);
            result->mCurrentValue.u.u8 = (uint8_t)env->GetIntField(mDatabase, field_batteryLevel);
            result->mCurrentValue.u.u8 = (uint8_t)env->GetIntField(mDatabase, field_batteryLevel);
            break;
            break;
        case MTP_DEVICE_PROPERTY_PERCEIVED_DEVICE_TYPE:
            result = new MtpProperty(property, MTP_TYPE_UINT32);
            result->mCurrentValue.u.u32 = (uint32_t)env->GetIntField(mDatabase, field_deviceType);
            break;
    }
    }


    checkAndClearExceptionFromCallback(env, __FUNCTION__);
    checkAndClearExceptionFromCallback(env, __FUNCTION__);
@@ -1388,6 +1394,11 @@ int register_android_mtp_MtpDatabase(JNIEnv *env)
        ALOGE("Can't find MtpDatabase.mBatteryScale");
        ALOGE("Can't find MtpDatabase.mBatteryScale");
        return -1;
        return -1;
    }
    }
    field_deviceType = env->GetFieldID(clazz, "mDeviceType", "I");
    if (field_deviceType == NULL) {
        ALOGE("Can't find MtpDatabase.mDeviceType");
        return -1;
    }


    // now set up fields for MtpPropertyList class
    // now set up fields for MtpPropertyList class
    clazz = env->FindClass("android/mtp/MtpPropertyList");
    clazz = env->FindClass("android/mtp/MtpPropertyList");