Changing Android hotspot settings

前端 未结 1 856
情话喂你
情话喂你 2020-12-28 10:57

With the release of API level 26, my app\'s core functionality broke, this being, changing the users\' hotspot setting within the application. To get and set this configura

1条回答
  •  星月不相逢
    2020-12-28 11: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

    
    
    

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

    0 讨论(0)
提交回复
热议问题