1、wifi原生setting的入口在WifiTetherSettings.java
packages/apps/Settings/src/com/android/settings/wifi/tether/WifiTetherSettings.java
- WifiTetherSettings???????层
开启热点和关闭热点的最后是使用ConnectivityManager的 startTethering 和 stopTethering
packages/apps/Settings/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java
void stopTether() {
mSwitchBar.setEnabled(false);
mConnectivityManager.stopTethering(TETHERING_WIFI);
}
void startTether() {
mSwitchBar.setEnabled(false);
mConnectivityManager.startTethering(TETHERING_WIFI, true /* showProvisioningUi */,
mOnStartTetheringCallback, new Handler(Looper.getMainLooper()));
}
frameworks/base/core/java/android/net/ConnectivityManager.java
public void startTethering(int type, boolean showProvisioningUi,
final OnStartTetheringCallback callback, Handler handler) {
mTetheringManager.startTethering(request, executor, tetheringCallback);
}
public void stopTethering(int type) {
mTetheringManager.stopTethering(type);
}
frameworks/base/packages/Tethering/common/TetheringLib/src/android/net/TetheringManager.java
调用到Tethering
public void startTethering(@NonNull final TetheringRequest request,
@NonNull final Executor executor, @NonNull final StartTetheringCallback callback) {
getConnector(c -> c.startTethering(request.getParcel(), callerPkg, listener));
}
public void stopTethering(@TetheringType final int type) {
getConnector(c -> c.stopTethering(type, callerPkg, new IIntResultListener.Stub() {
@Override
public void onResult(int resultCode) {
}
}));
}
?
frameworks/base/packages/Tethering/src/com/android/networkstack/tethering/Tethering.java
最后startTethering调用到最后是WifiManager.startTetheredHotspot,
stopTethering 调用到最后是WifiManager.stopSoftAp
void startTethering(final TetheringRequestParcel request, final IIntResultListener listener) {
mHandler.post(() -> {
enableTetheringInternal(request.tetheringType, true /* enabled */, listener);
});
}
private void enableTetheringInternal(int type, boolean enable,
final IIntResultListener listener) {
int result = TETHER_ERROR_NO_ERROR;
switch (type) {
case TETHERING_WIFI:
result = setWifiTethering(enable);
break;
case TETHERING_USB:
result = setUsbTethering(enable);
break;
case TETHERING_BLUETOOTH:
setBluetoothTethering(enable, listener);
break;
default:
Log.w(TAG, "Invalid tether type.");
result = TETHER_ERROR_UNKNOWN_TYPE;
}
}
private int setWifiTethering(final boolean enable) {
final WifiManager mgr = getWifiManager();
if ((enable && mgr.startTetheredHotspot(null /* use existing softap config */))
|| (!enable && mgr.stopSoftAp())) {
mWifiTetherRequested = enable;
return TETHER_ERROR_NO_ERROR;
}
}
2、改热点Setting的时候可以直接只编译Settings.apk,并且替换,可以查看Android.bp文件
./system_ext/priv-app/Settings/Settings.apk
|