Make users of MtpServer fill in DeviceInfo field values
This is part of weaning apps off accessing system identifiers via
system properties API. Apps should use android.os.Build API instead.
Bug: 33700679
Test: Enable MTP mode then check that mtp-detect output same as before this commit
Change-Id: I4e6696cdee18b9c3e987c432c095911e85a997db
diff --git a/media/jni/android_mtp_MtpServer.cpp b/media/jni/android_mtp_MtpServer.cpp
index afd3082..c325f4e 100644
--- a/media/jni/android_mtp_MtpServer.cpp
+++ b/media/jni/android_mtp_MtpServer.cpp
@@ -61,10 +61,34 @@
}
static void
-android_mtp_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jboolean usePtp)
+android_mtp_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jboolean usePtp,
+ jstring deviceInfoManufacturer,
+ jstring deviceInfoModel,
+ jstring deviceInfoDeviceVersion,
+ jstring deviceInfoSerialNumber)
{
+ const char *deviceInfoManufacturerStr = env->GetStringUTFChars(deviceInfoManufacturer, NULL);
+ const char *deviceInfoModelStr = env->GetStringUTFChars(deviceInfoModel, NULL);
+ const char *deviceInfoDeviceVersionStr = env->GetStringUTFChars(deviceInfoDeviceVersion, NULL);
+ const char *deviceInfoSerialNumberStr = env->GetStringUTFChars(deviceInfoSerialNumber, NULL);
MtpServer* server = new MtpServer(getMtpDatabase(env, javaDatabase),
- usePtp, AID_MEDIA_RW, 0664, 0775);
+ usePtp, AID_MEDIA_RW, 0664, 0775,
+ MtpString((deviceInfoManufacturerStr != NULL) ? deviceInfoManufacturerStr : ""),
+ MtpString((deviceInfoModelStr != NULL) ? deviceInfoModelStr : ""),
+ MtpString((deviceInfoDeviceVersionStr != NULL) ? deviceInfoDeviceVersionStr : ""),
+ MtpString((deviceInfoSerialNumberStr != NULL) ? deviceInfoSerialNumberStr : ""));
+ if (deviceInfoManufacturerStr != NULL) {
+ env->ReleaseStringUTFChars(deviceInfoManufacturer, deviceInfoManufacturerStr);
+ }
+ if (deviceInfoModelStr != NULL) {
+ env->ReleaseStringUTFChars(deviceInfoModel, deviceInfoModelStr);
+ }
+ if (deviceInfoDeviceVersionStr != NULL) {
+ env->ReleaseStringUTFChars(deviceInfoDeviceVersion, deviceInfoDeviceVersionStr);
+ }
+ if (deviceInfoSerialNumberStr != NULL) {
+ env->ReleaseStringUTFChars(deviceInfoSerialNumber, deviceInfoSerialNumberStr);
+ }
env->SetLongField(thiz, field_MtpServer_nativeContext, (jlong)server);
}
@@ -180,7 +204,7 @@
static const JNINativeMethod gMethods[] = {
{"native_configure", "(Z)V", (void *)android_mtp_configure},
- {"native_setup", "(Landroid/mtp/MtpDatabase;Z)V",
+ {"native_setup", "(Landroid/mtp/MtpDatabase;ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
(void *)android_mtp_MtpServer_setup},
{"native_run", "()V", (void *)android_mtp_MtpServer_run},
{"native_cleanup", "()V", (void *)android_mtp_MtpServer_cleanup},