Class Info |
|---|
public class DeviceVpnManager VPN相关管理类。 |
Qualifier and Type | Method Name and Description |
|---|---|
boolean | setVpnDisabled(ComponentName admin, boolean isDisabled) 禁用/启用 VPN。 |
boolean | isVpnDisabled(ComponentName admin) 查询 VPN 的禁用状态。 |
boolean | setVpnProfile(ComponentName admin, DeviceVpnProfile profile) 配置VPN。 |
boolean | deleteVpnProfile(ComponentName admin, String key) 删除VPN。 |
List<String> | getVpnList(ComponentName admin) 获取VPN 列表。 |
DeviceVpnProfile | getVpnProfile(ComponentName admin, String key) 根据指定的 key 获取对应的 VPN 文件。 |
boolean | setInsecureVpnDisabled(ComponentName admin, boolean isDisabled) 设置仅允许使用安全VPN。 |
boolean | isInsecureVpnDisabled(ComponentName admin) 获取仅允许使用安全VPN的禁用状态。 |
boolean | setShowVpnPasswordDisabled(ComponentName admin, boolean isDisabled) 禁用/启用VPN 密码编辑框的查看功能。 |
boolean | isShowVpnPasswordDisabled(ComponentName admin) 查询VPN密码编辑框的查看功能状态。 |
Supported Devices
Device Type | OS Version |
|---|---|
手机、平板 | EMUI 5.1及以上或HarmonyOS 2.0及以上 |
Method |
|---|
public boolean setVpnDisabled(ComponentName admin, boolean isDisabled) 设置手机的VPN禁用策略。当禁用手机VPN时,会断掉已经连接的VPN,手机的VPN界面会置灰,不可编辑,同时也不可以通过三方应用连接VPN。当允许使用时,手机的 VPN功能恢复正常。 注意:需要申请com.huawei.permission.sec.MDM_VPN权限。 |
Parameters
Name | Description |
|---|---|
admin | 调用该接口的组件名称,不能为null。 |
isDisabled |
|
Return
Type | Description |
|---|---|
boolean |
|
Throws
Name | Description |
|---|---|
SecurityException |
|
IllegalArgumentException | 参数错误或admin为null。 |
Supported Devices
Device Type | OS Version |
|---|---|
手机、平板 | EMUI 5.1及以上或HarmonyOS 2.0及以上 |
Method |
|---|
public boolean isVpnDisabled(ComponentName admin) 获取手机中的VPN禁用策略。 |
Parameters
Name | Description |
|---|---|
admin | 调用该接口的组件名称,查询该应用配置的策略;参数为null时,获取所有应用设置的综合策略结果。 |
Return
Type | Description |
|---|---|
boolean |
|
Supported Devices
Device Type | OS Version |
|---|---|
手机、平板 | EMUI 5.1及以上或HarmonyOS 2.0及以上 |
Method |
|---|
public boolean setVpnProfile(ComponentName admin, DeviceVpnProfile profile) 配置手机中的VPN,配置文件profile中有关键字key来区分各个VPN,若key已存在则修改已配置的VPN,若key不存在则增加一个新的VPN。 注意:需要申请com.huawei.permission.sec.MDM_VPN权限。 |
Parameters
Name | Description |
|---|---|
admin | 调用该接口的组件名称,不能为null。 |
profile | 存放VPN的配置。 |
DeviceVpnProfile构造方法 | 说明 |
|---|---|
public DeviceVpnProfile(String key) | 传入key构造,其余使用默认值,String类型为“”,type为0,mppe 为true。 |
public DeviceVpnProfile(String key, String name, int type, String server,String username, String password, boolean mppe, String l2tpSecret,String ipsecIdentifier, String ipsecSecret, String ipsecUserCert,String ipsecCaCert, String ipsecServerCert) | 传入所有的属性的参数。 |
属性类型 | 属性名称 | 说明 |
|---|---|---|
String | key | VPN的唯一标识,不可为null,不可为空字符串。 |
String | name | VPN的名称。 |
int | type | VPN 的类型,有效范围 0-6。
|
String | server | 服务器名称。 |
String | username | 用户名。 |
String | password | 密码。 |
boolean | mppe | PPP加密。 |
String | l2tpSecret | L2TP密钥。 |
String | ipsecIdentifier | IPSec标识符。 |
String | ipsecSecret | IPSec预共享密钥。 |
String | ipsecUserCert | IPSec用户证书。 |
String | ipsecCaCert | IPSec CA证书. |
String | ipsecServerCert | IPSec 服务器证书。 |
Return
Type | Description |
|---|---|
boolean |
|
Throws
Name | Description |
|---|---|
SecurityException |
|
IllegalArgumentException | 参数错误或admin 为null。 |
Supported Devices
Device Type | OS Version |
|---|---|
手机、平板 | EMUI 5.1及以上或HarmonyOS 2.0及以上 |
Method |
|---|
public boolean deleteVpnProfile(ComponentName admin, String key) 根据传入的key来删除手机中的VPN,若存在该key的VPN则删除,若不存在该VPN则返回失败。 注意:需要申请com.huawei.permission.sec.MDM_VPN权限。 |
Parameters
Name | Description |
|---|---|
admin | 调用该接口的组件名称,不能为null。 |
key | 用来区分VPN的标识。 |
Return
Type | Description |
|---|---|
boolean |
|
Throws
Name | Description |
|---|---|
SecurityException |
|
IllegalArgumentException | 参数错误,或admin为null。 |
Supported Devices
Device Type | OS Version |
|---|---|
手机、平板 | EMUI 5.1及以上或HarmonyOS 2.0及以上 |
Method |
|---|
public List<String> getVpnList(ComponentName admin) 获取手机中的所有的 VPN 的 key 组成的列表。 |
Parameters
Name | Description |
|---|---|
admin | 调用该接口的应用的组件名称。参数admin若不为空,则获取的是本应用配置的VPN的key组成的列表;若admin为空则获取的是手机中所有应用配置的VPN的key组成的列表。 |
Return
Type | Description |
|---|---|
List<String> | VPN的key组成的列表。若没有配置VPN,则返回一个空表。 |
Supported Devices
Device Type | OS Version |
|---|---|
手机、平板 | EMUI 5.1及以上或HarmonyOS 2.0及以上 |
Method |
|---|
public DeviceVpnProfile getVpnProfile(ComponentName admin, String key) 根据指定的key获取对应的VPN文件,若不存在则返回null。 |
Parameters
Name | Description |
|---|---|
admin | 调用该接口的组件名称,查询该应用配置的策略;参数为null时,获取所有应用设置的综合策略结果。 |
key | VPN的唯一标识,用来获取VPN配置文件。 |
Return
Type | Description |
|---|---|
DeviceVpnProfile | 传入的key所对应的VPN配置文件。 |
Throws
Name | Description |
|---|---|
SecurityException | 此APK未经设备管理激活。 |
Supported Devices
Device Type | OS Version |
|---|---|
手机、平板 | EMUI 8.0及以上或HarmonyOS 2.0及以上 |
Method |
|---|
public boolean setInsecureVpnDisabled(ComponentName admin, boolean isDisabled) 设置手机中不安全VPN的禁用策略。 注意:需要申请com.huawei.permission.sec.MDM_VPN权限。 |
Parameters
Name | Description |
|---|---|
admin | 调用该接口的组件名称。 |
isDisabled |
|
Return
Type | Description |
|---|---|
boolean |
|
Throws
Name | Description |
|---|---|
SecurityException |
|
IllegalArgumentException | 参数错误,或admin为null。 |
Supported Devices
Device Type | OS Version |
|---|---|
手机、平板 | EMUI 8.0及以上或HarmonyOS 2.0及以上 |
Method |
|---|
public boolean isInsecureVpnDisabled(ComponentName admin) 获取手机中不安全VPN的禁用策略。 |
Parameters
Name | Description |
|---|---|
admin | 调用该接口的组件名称,查询该应用配置的策略;参数为null时,获取所有应用设置的综合策略结果。 |
Return
Type | Description |
|---|---|
boolean |
|
Supported Devices
Device Type | OS Version |
|---|---|
手机、平板 | EMUI 10.1.0及以上或HarmonyOS 2.0及以上 |
Method |
|---|
public boolean setShowVpnPasswordDisabled(ComponentName admin, boolean isDisabled) 禁用/启用VPN密码编辑框的查看功能。 注意:需要申请com.huawei.permission.sec.MDM_VPN权限。 |
Parameters
Name | Description |
|---|---|
admin | 调用该接口的组件名称。 |
isDisabled |
|
Return
Type | Description |
|---|---|
boolean |
|
Throws
Name | Description |
|---|---|
SecurityException |
|
IllegalArgumentException | 参数错误,或admin为null。 |
Supported Devices
Device Type | OS Version |
|---|---|
手机、平板 | EMUI 10.1.0及以上或HarmonyOS 2.0及以上 |
Method |
|---|
public boolean isShowVpnPasswordDisabled(ComponentName admin) 查询VPN密码编辑框的查看功能是否禁用。 |
Parameters
Name | Description |
|---|---|
admin | 调用该接口的组件名称。为null时,获取的是全局综合策略结果。 |
Return
Type | Description |
|---|---|
boolean |
|