-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/search domain for android (#1256)
Support search domain on Android - pass list of search domains to Android SDK - throw notification in case of search domain changes
- Loading branch information
Showing
15 changed files
with
180 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package dns | ||
|
||
import ( | ||
"reflect" | ||
"sort" | ||
"sync" | ||
|
||
"github.com/netbirdio/netbird/client/internal/listener" | ||
) | ||
|
||
type notifier struct { | ||
listener listener.NetworkChangeListener | ||
listenerMux sync.Mutex | ||
searchDomains []string | ||
} | ||
|
||
func newNotifier(initialSearchDomains []string) *notifier { | ||
sort.Strings(initialSearchDomains) | ||
return ¬ifier{ | ||
searchDomains: initialSearchDomains, | ||
} | ||
} | ||
|
||
func (n *notifier) setListener(listener listener.NetworkChangeListener) { | ||
n.listenerMux.Lock() | ||
defer n.listenerMux.Unlock() | ||
n.listener = listener | ||
} | ||
|
||
func (n *notifier) onNewSearchDomains(searchDomains []string) { | ||
sort.Strings(searchDomains) | ||
|
||
if len(n.searchDomains) != len(searchDomains) { | ||
n.searchDomains = searchDomains | ||
n.notify() | ||
return | ||
} | ||
|
||
if reflect.DeepEqual(n.searchDomains, searchDomains) { | ||
return | ||
} | ||
|
||
n.searchDomains = searchDomains | ||
n.notify() | ||
} | ||
|
||
func (n *notifier) notify() { | ||
n.listenerMux.Lock() | ||
defer n.listenerMux.Unlock() | ||
if n.listener == nil { | ||
return | ||
} | ||
|
||
go func(l listener.NetworkChangeListener) { | ||
l.OnNetworkChanged() | ||
}(n.listener) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package listener | ||
|
||
// NetworkChangeListener is a callback interface for mobile system | ||
type NetworkChangeListener interface { | ||
// OnNetworkChanged invoke when network settings has been changed | ||
OnNetworkChanged() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.