mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-01 19:18:28 -04:00
feat(network): initial WiFi hotspot support (#2825)
* Add hotspot contract layer with capability-gated dispatch. Establish the interface and manager plumbing for hotspot support so backends can opt in without expanding the core Backend contract. Only backends that implement HotspotBackend get hotspot state propagated; others are forced to unsupported regardless of what they self-report. * Add IPC handlers and API docs for hotspot actions. Wire up configure/ start/ stop hotspot through the request router so the QML service layer can drive hotspot operations. Bump API version to 27 and document the capability-gating contract clients should follow. * Implement NetworkManager hotspot backend. Implement HotspotBackend on NetworkManagerBackend with DMS-owned profile management, AP capability detection, and band validation. Device resolution is deferred to StartHotspot when no device is specified, so profiles survive hardware changes. * Isolate client Wi-Fi state from AP-mode connections. Filter AP-mode profiles and access points out of all client Wi-Fi paths so the DMS hotspot (and user-created APs) never appear as saved networks, visible networks, or connected state. This protects existing client behavior before hotspot controls are exposed in the UI. * Prefer idle radios for automatic hotspot device selection. * Add hotspot properties and methods to QML service layer. Expose hotspot state and actions through DMSNetworkService, NetworkService, and LegacyNetworkService. Capability is gated on API version and backend-reported support, not backend name checks, and stays stable when Wi-Fi radio is disabled. * Add hotspot controls to Settings and Control Center. Settings shows a hotspot setup card as a sibling in the Wi-Fi tab with SSID, password, device, band, save, and start/ stop controls. Control Center shows a compact row that toggles a configured hotspot or routes to Settings for initial setup. Both stay visible when Wi-Fi is disabled, explaining the requirement instead of hiding. * Add translator context to hotspot strings.
This commit is contained in:
@@ -70,6 +70,29 @@ Singleton {
|
||||
property string targetPreference: ""
|
||||
property var savedWifiNetworks: []
|
||||
readonly property int savedWifiStateApiVersion: 26
|
||||
readonly property int hotspotApiVersion: 28
|
||||
property bool backendHotspotSupported: false
|
||||
property bool backendHotspotAvailable: false
|
||||
property bool backendHotspotConfigured: false
|
||||
property bool backendHotspotEnabled: false
|
||||
property bool backendHotspotActivating: false
|
||||
property bool backendHotspotSecured: false
|
||||
property string backendHotspotSSID: ""
|
||||
property string backendHotspotDevice: ""
|
||||
property string backendHotspotBand: ""
|
||||
property string backendHotspotLastError: ""
|
||||
readonly property bool hotspotSupported: DMSService.isConnected && networkAvailable && DMSService.apiVersion >= hotspotApiVersion && backendHotspotSupported
|
||||
readonly property bool hotspotAvailable: hotspotSupported && backendHotspotAvailable
|
||||
readonly property bool hotspotConfigured: hotspotSupported && backendHotspotConfigured
|
||||
readonly property bool hotspotEnabled: hotspotSupported && backendHotspotEnabled
|
||||
readonly property bool hotspotActivating: hotspotSupported && backendHotspotActivating
|
||||
readonly property bool hotspotSecured: hotspotSupported && backendHotspotSecured
|
||||
readonly property bool hotspotWouldDisconnectWifi: hotspotSupported && !hotspotEnabled && !hotspotActivating && hotspotTargetWouldDisconnectWifi(backendHotspotDevice, backendHotspotBand)
|
||||
readonly property string hotspotSSID: hotspotSupported ? backendHotspotSSID : ""
|
||||
readonly property string hotspotDevice: hotspotSupported ? backendHotspotDevice : ""
|
||||
readonly property string hotspotBand: hotspotSupported ? backendHotspotBand : ""
|
||||
property bool hotspotBusy: false
|
||||
property string hotspotError: ""
|
||||
property string connectionStatus: ""
|
||||
property string lastConnectionError: ""
|
||||
property bool passwordDialogShouldReopen: false
|
||||
@@ -318,6 +341,43 @@ Singleton {
|
||||
wifiDevices = state.wifiDevices || [];
|
||||
connectingDevice = state.connectingDevice || "";
|
||||
|
||||
if (DMSService.apiVersion >= hotspotApiVersion) {
|
||||
const supportsHotspot = state.hotspotSupported === true;
|
||||
const wasHotspotEnabled = backendHotspotEnabled;
|
||||
const wasHotspotActivating = backendHotspotActivating;
|
||||
backendHotspotSupported = supportsHotspot;
|
||||
backendHotspotAvailable = state.hotspotAvailable === true;
|
||||
backendHotspotConfigured = state.hotspotConfigured === true;
|
||||
backendHotspotEnabled = state.hotspotEnabled === true;
|
||||
backendHotspotActivating = state.hotspotActivating === true;
|
||||
backendHotspotSecured = state.hotspotSecured === true;
|
||||
backendHotspotSSID = state.hotspotSSID || "";
|
||||
backendHotspotDevice = state.hotspotDevice || "";
|
||||
backendHotspotBand = state.hotspotBand || "";
|
||||
backendHotspotLastError = state.hotspotLastError || "";
|
||||
|
||||
// Activation is asynchronous: only toast outcomes of starts we watched
|
||||
// begin, so restoring state after a shell restart stays silent.
|
||||
const watchedStart = wasHotspotActivating || hotspotBusy;
|
||||
if (watchedStart && !wasHotspotEnabled && backendHotspotEnabled) {
|
||||
ToastService.showInfo(I18n.tr("Hotspot started", "hotspot start success message"));
|
||||
} else if (wasHotspotActivating && !backendHotspotActivating && !backendHotspotEnabled && backendHotspotLastError) {
|
||||
hotspotError = backendHotspotLastError;
|
||||
ToastService.showError(I18n.tr("Failed to start hotspot", "hotspot start error title"), hotspotErrorMessage(backendHotspotLastError));
|
||||
}
|
||||
} else {
|
||||
backendHotspotSupported = false;
|
||||
backendHotspotAvailable = false;
|
||||
backendHotspotConfigured = false;
|
||||
backendHotspotEnabled = false;
|
||||
backendHotspotActivating = false;
|
||||
backendHotspotSecured = false;
|
||||
backendHotspotSSID = "";
|
||||
backendHotspotDevice = "";
|
||||
backendHotspotBand = "";
|
||||
backendHotspotLastError = "";
|
||||
}
|
||||
|
||||
currentWifiSSID = state.wifiSSID || "";
|
||||
wifiSignalStrength = state.wifiSignal || 0;
|
||||
|
||||
@@ -1026,6 +1086,137 @@ Singleton {
|
||||
});
|
||||
}
|
||||
|
||||
function configureHotspot(ssid, password = "", device = "", band = "", callback = null) {
|
||||
if (!hotspotSupported || hotspotBusy)
|
||||
return false;
|
||||
|
||||
const params = {
|
||||
ssid: ssid
|
||||
};
|
||||
if (password)
|
||||
params.password = password;
|
||||
if (device)
|
||||
params.device = device;
|
||||
if (band)
|
||||
params.band = band;
|
||||
|
||||
hotspotBusy = true;
|
||||
hotspotError = "";
|
||||
|
||||
DMSService.sendRequest("network.hotspot.configure", params, response => {
|
||||
hotspotBusy = false;
|
||||
if (response.error) {
|
||||
hotspotError = response.error;
|
||||
ToastService.showError(I18n.tr("Failed to configure hotspot", "hotspot configuration error title"), response.error);
|
||||
} else {
|
||||
Qt.callLater(() => getState());
|
||||
}
|
||||
if (callback)
|
||||
callback(response);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function startHotspot(callback = null) {
|
||||
if (!hotspotAvailable || hotspotBusy)
|
||||
return false;
|
||||
|
||||
hotspotBusy = true;
|
||||
hotspotError = "";
|
||||
|
||||
DMSService.sendRequest("network.hotspot.start", null, response => {
|
||||
hotspotBusy = false;
|
||||
if (response.error) {
|
||||
hotspotError = response.error;
|
||||
ToastService.showError(I18n.tr("Failed to start hotspot", "hotspot start error title"), response.error);
|
||||
} else {
|
||||
Qt.callLater(() => getState());
|
||||
}
|
||||
if (callback)
|
||||
callback(response);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function stopHotspot(callback = null) {
|
||||
if (!hotspotSupported || hotspotBusy)
|
||||
return false;
|
||||
|
||||
hotspotBusy = true;
|
||||
hotspotError = "";
|
||||
|
||||
DMSService.sendRequest("network.hotspot.stop", null, response => {
|
||||
hotspotBusy = false;
|
||||
if (response.error) {
|
||||
hotspotError = response.error;
|
||||
ToastService.showError(I18n.tr("Failed to stop hotspot", "hotspot stop error title"), response.error);
|
||||
} else {
|
||||
Qt.callLater(() => getState());
|
||||
}
|
||||
if (callback)
|
||||
callback(response);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function configureAndStartHotspot(ssid, password = "", device = "", band = "", callback = null) {
|
||||
return configureHotspot(ssid, password, device, band, configureResponse => {
|
||||
if (configureResponse.error) {
|
||||
if (callback)
|
||||
callback(configureResponse);
|
||||
return;
|
||||
}
|
||||
startHotspot(callback);
|
||||
});
|
||||
}
|
||||
|
||||
function getHotspotSecrets(callback) {
|
||||
if (!hotspotSupported) {
|
||||
if (callback)
|
||||
callback({
|
||||
error: "hotspot not supported"
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
DMSService.sendRequest("network.hotspot.getSecrets", null, response => {
|
||||
if (callback)
|
||||
callback(response);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function hotspotTargetWouldDisconnectWifi(device, band = "") {
|
||||
const devices = wifiDevices || [];
|
||||
const active = devices.find(d => d.connected);
|
||||
if (!active)
|
||||
return false;
|
||||
if (device) {
|
||||
const target = devices.find(d => d.name === device);
|
||||
return target ? target.connected : device === active.name;
|
||||
}
|
||||
// Band capabilities are not exposed per device, so a fixed-band automatic
|
||||
// selection cannot safely promise that an idle radio will be usable.
|
||||
if (band)
|
||||
return true;
|
||||
return !devices.some(d => d.apCapable && !d.connected && d.state === "disconnected" && d.name !== active.name);
|
||||
}
|
||||
|
||||
function hotspotErrorMessage(code) {
|
||||
switch (code) {
|
||||
case "hotspot-ip-config-failed":
|
||||
return I18n.tr("IP sharing setup failed. Check that dnsmasq is installed.", "hotspot IP configuration failure message");
|
||||
case "hotspot-supplicant-failed":
|
||||
return I18n.tr("The WiFi adapter could not start access point mode.", "hotspot adapter failure message");
|
||||
default:
|
||||
return I18n.tr("Hotspot activation failed.", "generic hotspot activation failure message");
|
||||
}
|
||||
}
|
||||
|
||||
function refreshSavedWifiNetworks() {
|
||||
if (!networkAvailable)
|
||||
return;
|
||||
|
||||
@@ -55,6 +55,19 @@ Singleton {
|
||||
property string targetPreference: activeService?.targetPreference ?? ""
|
||||
property var savedWifiNetworks: activeService?.savedWifiNetworks ?? []
|
||||
readonly property int savedWifiStateApiVersion: activeService?.savedWifiStateApiVersion ?? 26
|
||||
readonly property int hotspotApiVersion: activeService?.hotspotApiVersion ?? 28
|
||||
property bool hotspotSupported: activeService?.hotspotSupported ?? false
|
||||
property bool hotspotAvailable: activeService?.hotspotAvailable ?? false
|
||||
property bool hotspotConfigured: activeService?.hotspotConfigured ?? false
|
||||
property bool hotspotEnabled: activeService?.hotspotEnabled ?? false
|
||||
property bool hotspotActivating: activeService?.hotspotActivating ?? false
|
||||
property bool hotspotSecured: activeService?.hotspotSecured ?? false
|
||||
property bool hotspotWouldDisconnectWifi: activeService?.hotspotWouldDisconnectWifi ?? false
|
||||
property string hotspotSSID: activeService?.hotspotSSID ?? ""
|
||||
property string hotspotDevice: activeService?.hotspotDevice ?? ""
|
||||
property string hotspotBand: activeService?.hotspotBand ?? ""
|
||||
property bool hotspotBusy: activeService?.hotspotBusy ?? false
|
||||
property string hotspotError: activeService?.hotspotError ?? ""
|
||||
property string connectionStatus: activeService?.connectionStatus ?? ""
|
||||
property string lastConnectionError: activeService?.lastConnectionError ?? ""
|
||||
property bool passwordDialogShouldReopen: activeService?.passwordDialogShouldReopen ?? false
|
||||
@@ -312,6 +325,48 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
function configureHotspot(ssid, password = "", device = "", band = "", callback = null) {
|
||||
if (activeService && activeService.configureHotspot) {
|
||||
return activeService.configureHotspot(ssid, password, device, band, callback);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function startHotspot(callback = null) {
|
||||
if (activeService && activeService.startHotspot) {
|
||||
return activeService.startHotspot(callback);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function stopHotspot(callback = null) {
|
||||
if (activeService && activeService.stopHotspot) {
|
||||
return activeService.stopHotspot(callback);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function configureAndStartHotspot(ssid, password = "", device = "", band = "", callback = null) {
|
||||
if (activeService && activeService.configureAndStartHotspot) {
|
||||
return activeService.configureAndStartHotspot(ssid, password, device, band, callback);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getHotspotSecrets(callback) {
|
||||
if (activeService && activeService.getHotspotSecrets) {
|
||||
return activeService.getHotspotSecrets(callback);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function hotspotTargetWouldDisconnectWifi(device, band = "") {
|
||||
if (activeService && activeService.hotspotTargetWouldDisconnectWifi) {
|
||||
return activeService.hotspotTargetWouldDisconnectWifi(device, band);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function setWifiDeviceOverride(deviceName) {
|
||||
if (activeService && activeService.setWifiDeviceOverride) {
|
||||
activeService.setWifiDeviceOverride(deviceName);
|
||||
|
||||
Reference in New Issue
Block a user