MTK 平台 ROM 开发中普遍存在手机连接 PC 后,PC 端我的电脑里面,概率将当前手机的名称显示为以前连接过的手机名称的问题。
2035681-2ce76626335039e5.png
2035681-bf1cd9380d29ab6f.png

这里将最近一次基于 N0 的修改分享出来。(此方法也同样适用于M1)

解决方法:

修改 \frameworks\base\media\java\android\mtp\MtpDatabase.java

1、添加导包:

  1. ///START. Fix the display error on PC. By XiaFei, 20170503.
  2. import android.os.SystemProperties;/// M: Added Modification for ALPS00278882
  3. ///import com.mediatek.xlog.SXlog;
  4. ///import com.mediatek.xlog.Xlog;
  5. import java.lang.Integer;
  6. ///END. Fix the display error on PC. By XiaFei, 20170503.

2、添加具体处理代码:

  1. private int getDeviceProperty(int property, long[] outIntValue, char[] outStringValue) {
  2. /// 此处省略 N 行
  3. switch (property) {
  4. case MtpConstants.DEVICE_PROPERTY_SYNCHRONIZATION_PARTNER:
  5. case MtpConstants.DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME:
  6. // writable string properties kept in shared preferences
  7. String value = mDeviceProperties.getString(Integer.toString(property), "");
  8. int length = value.length();
  9. if (length > 255) {
  10. length = 255;
  11. }
  12. value.getChars(0, length, outStringValue, 0);
  13. outStringValue[length] = 0;
  14. ///START. Fix the display error on PC. By XiaFei, 20170503.
  15. // Return the device name for the PC display if the FriendlyName is empty!!
  16. String deviceName = SystemProperties.get("ro.product.name");
  17. int lengthDeviceName = deviceName.length();
  18. if (lengthDeviceName > 255) {
  19. lengthDeviceName = 255;
  20. }
  21. if(lengthDeviceName >0) {
  22. deviceName.getChars(0, lengthDeviceName, outStringValue, 0);
  23. outStringValue[lengthDeviceName] = 0;
  24. ///SXlog.d(TAG, "getDeviceProperty deviceName = " + deviceName + ", lengthDeviceName = " + lengthDeviceName);
  25. } else {
  26. ///SXlog.d(TAG, "getDeviceProperty lengthDeviceName = " + lengthDeviceName);
  27. }
  28. ///END. Fix the display error on PC. By XiaFei, 20170503.
  29. return MtpConstants.RESPONSE_OK;
  30. /// 此处省略 N 行
  31. }
  32. }