Changing Android hotspot settings

心已入冬 提交于 2019-11-30 05:28:33

As of Android Oreo (26), a new permission check was added to the service implementation of the getWifiApConfiguration() method:

Snippet from WifiServiceImpl.java

/**
 * see {@link WifiManager#getWifiApConfiguration()}
 * @return soft access point configuration
 * @throws SecurityException if the caller does not have permission to retrieve the softap
 * config
 */
@Override
public WifiConfiguration getWifiApConfiguration() {
    enforceAccessPermission();
    int uid = Binder.getCallingUid();
    // only allow Settings UI to get the saved SoftApConfig
    if (!mWifiPermissionsUtil.checkConfigOverridePermission(uid)) {
        // random apps should not be allowed to read the user specified config
        throw new SecurityException("App not allowed to read or update stored WiFi Ap config "
                + "(uid = " + uid + ")");
    }
    mLog.trace("getWifiApConfiguration uid=%").c(uid).flush();
    return mWifiStateMachine.syncGetWifiApConfiguration();
}

Digging into the code you will quickly find out that to successfully invoke this method your application must hold the android.permission.OVERRIDE_WIFI_CONFIG permission that is a system level protected permission:

Snippet from framework AndroidManifest.xml

<!-- @SystemApi @hide Allows an application to modify any wifi configuration, even if created
 by another application. Once reconfigured the original creator cannot make any further
 modifications.
 <p>Not for use by third-party applications. -->
<permission android:name="android.permission.OVERRIDE_WIFI_CONFIG"
    android:protectionLevel="signature|privileged" />

This means that your application needs to be signed by the platform key or be privileged to use this API.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!