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

Commit 13bb2f4d authored by Jerry Zhang's avatar Jerry Zhang
Browse files

Add support for MTP perceived device type property.

Property value is based on the particular device.
This allows some hosts (windows) to apply a device
specific icon in file explorer.

Test: Connect device to windows, verify new icon
Bug: 25360563
Change-Id: I9d3468ca8c01a6f0d42ad543aef11ed265b6c825
parent a83222e4
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.media.MediaScanner;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.provider.MediaStore;
import android.provider.MediaStore.Audio;
import android.provider.MediaStore.Files;
@@ -133,6 +134,8 @@ public class MtpDatabase implements AutoCloseable {
    private int mBatteryLevel;
    private int mBatteryScale;

    private int mDeviceType;

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

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

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

@@ -869,6 +874,10 @@ public class MtpDatabase implements AutoCloseable {
                outStringValue[imageSize.length()] = 0;
                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

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

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

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->mCurrentValue.u.u8 = (uint8_t)env->GetIntField(mDatabase, field_batteryLevel);
            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__);
@@ -1388,6 +1394,11 @@ int register_android_mtp_MtpDatabase(JNIEnv *env)
        ALOGE("Can't find MtpDatabase.mBatteryScale");
        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
    clazz = env->FindClass("android/mtp/MtpPropertyList");