修改wifi默认设备名

1.可检测到的wifi Ap hostname
wifi设备名会在framework/base/services/core/java/com/android/server/ConnectivityService.java中初始化:

  public ConnectivityService(Context context, INetworkManagementService netManager,
        INetworkStatsService statsService, INetworkPolicyManager policyManager) {
    ...
    mTrackerHandler = new NetworkStateTrackerHandler(handlerThread.getLooper());

    // setup our unique device name
    if (TextUtils.isEmpty(SystemProperties.get("net.hostname"))) {
        String id = Settings.Secure.getString(context.getContentResolver(),
                Settings.Secure.ANDROID_ID);
        if (id != null && id.length() > 0) {
            String name = new String("android-").concat(id);
            SystemProperties.set("net.hostname", name);
        }
    }
    ...
  }

所以,默认设置net.hostname就可以了。
2.wifi direct devicename
wifi direct 的devicename又不使用net.hostname,在:
framework/opt/net/wifi/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java中

    private String getPersistedDeviceName() {
        String deviceName = Settings.Global.getString(mContext.getContentResolver(),
                Settings.Global.WIFI_P2P_DEVICE_NAME);
        if (deviceName == null) {
            if (!TextUtils.isEmpty(mContext.getResources().getString(
                    R.string.def_wifi_direct_name))) {
                return mContext.getResources().getString(R.string.def_wifi_direct_name);
            }
            /* We use the 4 digits of the ANDROID_ID to have a friendly
             * default that has low likelihood of collision with a peer */
            String id = Settings.Secure.getString(mContext.getContentResolver(),
                    Settings.Secure.ANDROID_ID);
            return "Android_" + id.substring(0,4); 
        }
        return deviceName;
    }

方法中读取Global的属性WIFI_P2P_DEVICE_NAME,所以,要默认修改的话,只需要修改此Global的属性值就可以了。
在framework/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java中添加其默认值就可以了。

    private void loadGlobalSettings(SQLiteDatabase db) {
        SQLiteStatement stmt = null;
        try {
            stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
                    + " VALUES(?,?);");
        ...
                    // Add for wifi direct device name
            String deviceName = SystemProperties.get("net.hostname", "");
            if (!TextUtils.isEmpty(deviceName)) {
                loadSetting(stmt, Settings.Global.WIFI_P2P_DEVICE_NAME, deviceName);
            }
        } finally {
            if (stmt != null) stmt.close();
        }
    }

results matching ""

    No results matching ""