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

这里将最近一次基于 N0 的修改分享出来。(此方法也同样适用于M1)
解决方法:
修改 \frameworks\base\media\java\android\mtp\MtpDatabase.java
1、添加导包:
///START. Fix the display error on PC. By XiaFei, 20170503.import android.os.SystemProperties;/// M: Added Modification for ALPS00278882///import com.mediatek.xlog.SXlog;///import com.mediatek.xlog.Xlog;import java.lang.Integer;///END. Fix the display error on PC. By XiaFei, 20170503.
2、添加具体处理代码:
private int getDeviceProperty(int property, long[] outIntValue, char[] outStringValue) {/// 此处省略 N 行switch (property) {case MtpConstants.DEVICE_PROPERTY_SYNCHRONIZATION_PARTNER:case MtpConstants.DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME:// writable string properties kept in shared preferencesString value = mDeviceProperties.getString(Integer.toString(property), "");int length = value.length();if (length > 255) {length = 255;}value.getChars(0, length, outStringValue, 0);outStringValue[length] = 0;///START. Fix the display error on PC. By XiaFei, 20170503.// Return the device name for the PC display if the FriendlyName is empty!!String deviceName = SystemProperties.get("ro.product.name");int lengthDeviceName = deviceName.length();if (lengthDeviceName > 255) {lengthDeviceName = 255;}if(lengthDeviceName >0) {deviceName.getChars(0, lengthDeviceName, outStringValue, 0);outStringValue[lengthDeviceName] = 0;///SXlog.d(TAG, "getDeviceProperty deviceName = " + deviceName + ", lengthDeviceName = " + lengthDeviceName);} else {///SXlog.d(TAG, "getDeviceProperty lengthDeviceName = " + lengthDeviceName);}///END. Fix the display error on PC. By XiaFei, 20170503.return MtpConstants.RESPONSE_OK;/// 此处省略 N 行}}
