Android M:无法以编程方式删除WIFI AP

Android M:无法以编程方式删除WIFI AP,android,android-wifi,wifimanager,Android,Android Wifi,Wifimanager,在安卓M中:我使用下面的代码删除当前连接的WIFI AP void RemoveConnectedNetwork(){ int ID=_wifiManager.getConnectionInfo().getNetworkId(); Log.d("test", "network id = ["+ID+"]"); boolen ret =_wifiManager.removeNetwork(ID); Log.d("test", "removeNetwork retur

在安卓M中:我使用下面的代码删除当前连接的WIFI AP

void RemoveConnectedNetwork(){
    int ID=_wifiManager.getConnectionInfo().getNetworkId();
    Log.d("test", "network id = ["+ID+"]");
    boolen ret =_wifiManager.removeNetwork(ID);
    Log.d("test", "removeNetwork return ="+ret);
    _wifiManager.saveConfiguration();
}
但是
RemoveConnectedNetwork()
总是返回false

尽管此API在以前的版本中运行良好

使用安卓M中的任何其他API可以在这个平台上实现任何解决方案


谢谢。

Android 6.0中的Wifi管理器有一些更改

如果WIFI\u Device\u Owner\u CONFIGS\u LOCKDOWN非零,则用户不能再修改或删除由活动设备所有者创建的任何Wi-Fi配置

用户仍然可以创建和修改自己的Wi-Fi配置

活动设备所有者有权编辑或删除任何Wi-Fi配置,包括非由其创建的配置

有关更多详细信息,请参阅此链接:

自Android M应用程序起,不允许修改未创建的网络。如果应用程序本身配置了任何网络,则可以从该应用程序中删除该网络。 在调用removeNetwork(int)后,从“WifiConfigManager”检查日志,您将得到一个错误,例如UID(应用程序UID)没有删除配置的权限(“wifi SSID”功能)

原因很多,请参阅以下代码和链接以了解更多详细信息。


谢谢从谷歌收到了类似的回复@
/**
 * Checks if |uid| has permission to modify the provided configuration.
 *
 * @param config         WifiConfiguration object corresponding to the network to be modified.
 * @param uid            UID of the app requesting the modification.
 * @param ignoreLockdown Ignore the configuration lockdown checks for connection attempts.
 */
private boolean canModifyNetwork(WifiConfiguration config, int uid, boolean ignoreLockdown) {
    // System internals can always update networks; they're typically only
    // making meteredHint or meteredOverride changes
    if (uid == Process.SYSTEM_UID) {
        return true;
    }
    // Passpoint configurations are generated and managed by PasspointManager. They can be
    // added by either PasspointNetworkEvaluator (for auto connection) or Settings app
    // (for manual connection), and need to be removed once the connection is completed.
    // Since it is "owned" by us, so always allow us to modify them.
    if (config.isPasspoint() && uid == Process.WIFI_UID) {
        return true;
    }
    // EAP-SIM/AKA/AKA' network needs framework to update the anonymous identity provided
    // by authenticator back to the WifiConfiguration object.
    // Since it is "owned" by us, so always allow us to modify them.
    if (config.enterpriseConfig != null
            && uid == Process.WIFI_UID
            && TelephonyUtil.isSimEapMethod(config.enterpriseConfig.getEapMethod())) {
        return true;
    }
    final DevicePolicyManagerInternal dpmi = LocalServices.getService(
            DevicePolicyManagerInternal.class);
    final boolean isUidDeviceOwner = dpmi != null && dpmi.isActiveAdminWithPolicy(uid,
            DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
    // If |uid| corresponds to the device owner, allow all modifications.
    if (isUidDeviceOwner) {
        return true;
    }
    final boolean isCreator = (config.creatorUid == uid);
    // Check if the |uid| holds the |NETWORK_SETTINGS| permission if the caller asks us to
    // bypass the lockdown checks.
    if (ignoreLockdown) {
        return mWifiPermissionsUtil.checkNetworkSettingsPermission(uid);
    }
    // Check if device has DPM capability. If it has and |dpmi| is still null, then we
    // treat this case with suspicion and bail out.
    if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN)
            && dpmi == null) {
        Log.w(TAG, "Error retrieving DPMI service.");
        return false;
    }
    // WiFi config lockdown related logic. At this point we know uid is NOT a Device Owner.
    final boolean isConfigEligibleForLockdown = dpmi != null && dpmi.isActiveAdminWithPolicy(
            config.creatorUid, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
    if (!isConfigEligibleForLockdown) {
        return isCreator || mWifiPermissionsUtil.checkNetworkSettingsPermission(uid);
    }
    final ContentResolver resolver = mContext.getContentResolver();
    final boolean isLockdownFeatureEnabled = Settings.Global.getInt(resolver,
            Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, 0) != 0;
    return !isLockdownFeatureEnabled
            && mWifiPermissionsUtil.checkNetworkSettingsPermission(uid);
}