MTP: Implement MTP_DEVICE_PROPERTY_IMAGE_SIZE device property.
Return screen size as preferred maximum image size. Change-Id: I8dc4afb0e49fe45f6925a35aa443d3fc30211453 Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
@@ -31,6 +31,8 @@ import android.provider.MediaStore.Files;
|
||||
import android.provider.MediaStore.Images;
|
||||
import android.provider.MediaStore.MediaColumns;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
@@ -460,6 +462,7 @@ public class MtpDatabase {
|
||||
return new int[] {
|
||||
MtpConstants.DEVICE_PROPERTY_SYNCHRONIZATION_PARTNER,
|
||||
MtpConstants.DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME,
|
||||
MtpConstants.DEVICE_PROPERTY_IMAGE_SIZE,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -592,9 +595,21 @@ public class MtpDatabase {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return MtpConstants.RESPONSE_DEVICE_PROP_NOT_SUPPORTED;
|
||||
case MtpConstants.DEVICE_PROPERTY_IMAGE_SIZE:
|
||||
// use screen size as max image size
|
||||
Display display = ((WindowManager)mContext.getSystemService(
|
||||
Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||
int width = display.getWidth();
|
||||
int height = display.getHeight();
|
||||
String imageSize = Integer.toString(width) + "x" + Integer.toString(height);
|
||||
imageSize.getChars(0, imageSize.length(), outStringValue, 0);
|
||||
outStringValue[imageSize.length()] = 0;
|
||||
return MtpConstants.RESPONSE_OK;
|
||||
|
||||
default:
|
||||
return MtpConstants.RESPONSE_DEVICE_PROP_NOT_SUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
private int setDeviceProperty(int property, long intValue, String stringValue) {
|
||||
|
||||
@@ -860,8 +860,9 @@ static const PropertyTableEntry kObjectPropertyTable[] = {
|
||||
};
|
||||
|
||||
static const PropertyTableEntry kDevicePropertyTable[] = {
|
||||
{ MTP_DEVICE_PROPERTY_SYNCHRONIZATION_PARTNER, MTP_TYPE_STR },
|
||||
{ MTP_DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME, MTP_TYPE_STR },
|
||||
{ MTP_DEVICE_PROPERTY_SYNCHRONIZATION_PARTNER, MTP_TYPE_STR },
|
||||
{ MTP_DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME, MTP_TYPE_STR },
|
||||
{ MTP_DEVICE_PROPERTY_IMAGE_SIZE, MTP_TYPE_STR },
|
||||
};
|
||||
|
||||
bool MyMtpDatabase::getObjectPropertyInfo(MtpObjectProperty property, int& type) {
|
||||
@@ -973,31 +974,35 @@ MtpProperty* MyMtpDatabase::getObjectPropertyDesc(MtpObjectProperty property,
|
||||
}
|
||||
|
||||
MtpProperty* MyMtpDatabase::getDevicePropertyDesc(MtpDeviceProperty property) {
|
||||
JNIEnv* env = AndroidRuntime::getJNIEnv();
|
||||
MtpProperty* result = NULL;
|
||||
bool writable = false;
|
||||
|
||||
switch (property) {
|
||||
case MTP_DEVICE_PROPERTY_SYNCHRONIZATION_PARTNER:
|
||||
case MTP_DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME:
|
||||
{
|
||||
// writeable string properties
|
||||
result = new MtpProperty(property, MTP_TYPE_STR, true);
|
||||
writable = true;
|
||||
// fall through
|
||||
case MTP_DEVICE_PROPERTY_IMAGE_SIZE:
|
||||
result = new MtpProperty(property, MTP_TYPE_STR, writable);
|
||||
|
||||
// set current value
|
||||
JNIEnv* env = AndroidRuntime::getJNIEnv();
|
||||
// get current value
|
||||
jint ret = env->CallIntMethod(mDatabase, method_getDeviceProperty,
|
||||
(jint)property, mLongBuffer, mStringBuffer);
|
||||
if (ret == MTP_RESPONSE_OK) {
|
||||
jchar* str = env->GetCharArrayElements(mStringBuffer, 0);
|
||||
result->setCurrentValue(str);
|
||||
// for read-only properties it is safe to assume current value is default value
|
||||
if (!writable)
|
||||
result->setDefaultValue(str);
|
||||
env->ReleaseCharArrayElements(mStringBuffer, str, 0);
|
||||
} else {
|
||||
LOGE("unable to read device property, response: %04X", ret);
|
||||
}
|
||||
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
checkAndClearExceptionFromCallback(env, __FUNCTION__);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user