Skip to content

Commit

Permalink
IOS App Env Setup (#883)
Browse files Browse the repository at this point in the history
* Updated App icon.

* Updated Name.

* Updated Launch scren icons

* Started working on Basic channel setup.

* setup lantern_event_channel.

* Establish session model channel.

* Setup navigation and other channles.

* Added flashlight as submodule.

* Move ios resource to current repo.

* Added new files.

* Make changes on makefile to generate binding for ios.

* Created Logger

* Setup go method channel handler/

* Added module

* Added support for multiple channel.

* clean up.

* Added changes to event lisnter.

* Added db connection outline.

* Started working on baseModel.

* Updated path db and added support for minisql

* Make changes code to support new sql.

* Updated Swift code to support new pathDb.

* Expose multiple DB method.

* Updates Session Model to use GO method call.

* Added support for Subscribe and unSubscribe and generic models.

* Removed unused code.

* unsubscribe when not needed.

* Added changes on DB mannger.

* Generated bindings.

* Added few more changes.

* Updated dependencies

* Get value once add it.

* Fixed issue with not getting values from Scan

* Complete Implementation for Base Model.

* implemented changes for Method call.

* Create model in go and Swift.

* Implemented Session interface in session model.

* Implemented utils class and more changes to session model.

* Return error on method.

* Remove flashlight as submodule.

---------

Co-authored-by: Ox Cart <[email protected]>
  • Loading branch information
jigar-f and oxtoacart authored Aug 30, 2023
1 parent b8c5aa9 commit 37d1b35
Show file tree
Hide file tree
Showing 44 changed files with 3,554 additions and 330 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ android/app/libs/opuslib-release.aar filter=lfs diff=lfs merge=lfs -text
screenshots/ filter=lfs diff=lfs merge=lfs -text
assets/testing/ filter=lfs diff=lfs merge=lfs -text
android/app/libs/alipaySdk-15.7.6-20200521195109.aar filter=lfs diff=lfs merge=lfs -text
Internalsdk.xcframework filter=lfs diff=lfs merge=lfs -text
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ web*.pem
screenshots
profile.cov
appium_kotlin/app/src/test/resources/local/local_config.json

ios/internalsdk/Internalsdk.xcframework/
51 changes: 50 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#1 Disable implicit rules
.SUFFIXES:

.PHONY: codegen protos routes mocks test integration-test sourcedump
.PHONY: codegen protos routes mocks test integration-test sourcedump build-framework build-framework-debug clean archive require-version set-version show-version reset-build-number install-gomobile assert-go-version

INTERNALSDK_FRAMEWORK_DIR = ios/internalsdk
INTERNALSDK_FRAMEWORK_NAME = Internalsdk.xcframework


codegen: protos routes

Expand Down Expand Up @@ -464,6 +468,46 @@ sourcedump: require-version
find vendor/github.com/getlantern -name LICENSE -exec rm {} \; && \
tar -czf $$here/lantern-android-sources-$$VERSION.tar.gz .

build-framework: assert-go-version install-gomobile
@echo "Nuking $(INTERNALSDK_FRAMEWORK_DIR) and $(MINISQL_FRAMEWORK_DIR)"
rm -Rf $(INTERNALSDK_FRAMEWORK_DIR) $(MINISQL_FRAMEWORK_DIR)
@echo "generating Ios.xcFramework"
go env -w 'GOPRIVATE=github.com/getlantern/*' && \
gomobile init && \
gomobile bind -target=ios \
-tags='headless lantern ios' \
-ldflags="$(LDFLAGS)" \
$(GOMOBILE_EXTRA_BUILD_FLAGS) \
github.com/getlantern/android-lantern/internalsdk github.com/getlantern/pathdb/minisql
@echo "moving framework"
mkdir -p $(INTERNALSDK_FRAMEWORK_DIR)
mv ./$(INTERNALSDK_FRAMEWORK_NAME) $(INTERNALSDK_FRAMEWORK_DIR)/$(INTERNALSDK_FRAMEWORK_NAME)

#build-framework: assert-go-version install-gomobile
# @echo "Nuking $(FRAMEWORK_DIR)"
# rm -Rf $(FRAMEWORK_DIR)
# @echo "generating Ios.xcFramework"
# go env -w 'GOPRIVATE=github.com/getlantern/*' && \
# gomobile init && \
# gomobile bind -target=ios \
# -tags='headless lantern ios' \
# -ldflags="$(LDFLAGS)" \
# $(GOMOBILE_EXTRA_BUILD_FLAGS) \
# $(ANDROID_LIB_PKG)
# @echo "copying framework"
# mkdir -p $(FRAMEWORK_DIR)/$(FRAMEWORK_NAME)
# cp -R ./$(FRAMEWORK_NAME)/* $(FRAMEWORK_DIR)/$(FRAMEWORK_NAME)
# @echo "Nuking $(FRAMEWORK_NAME)"
# rm -Rf ./$(FRAMEWORK_NAME)


install-gomobile:
@echo "installing gomobile" && \
go install golang.org/x/mobile/cmd/gomobile@latest

assert-go-version:
@if go version | grep -q -v $(GO_VERSION); then echo "go $(GO_VERSION) is required." && exit 1; fi

clean:
rm -f liblantern*.aar && \
rm -f $(MOBILE_LIBS)/liblantern-* && \
Expand All @@ -472,3 +516,8 @@ clean:
rm -Rf *.apk && \
rm -f `which gomobile` && \
rm -f `which gobind`
rm -Rf "$(FLASHLIGHT_FRAMEWORK_PATH)" "$(INTERMEDIATE_FLASHLIGHT_FRAMEWORK_PATH)"




66 changes: 46 additions & 20 deletions android/app/src/main/kotlin/io/lantern/model/BaseModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@ abstract class BaseModel(
init {
val start = System.currentTimeMillis()
val context = LanternApp.getAppContext()
Logger.debug(TAG, "LanternApp.getAppContext() finished at ${System.currentTimeMillis() - start}")
val oldSecretsPreferences = context.getSharedPreferences("secrets", Context.MODE_PRIVATE)
Logger.debug(
TAG,
"LanternApp.getAppContext() finished at ${System.currentTimeMillis() - start}"
)
val oldSecretsPreferences =
context.getSharedPreferences("secrets", Context.MODE_PRIVATE)
val secretsPreferences = context.getSharedPreferences("secretsv2", Context.MODE_PRIVATE)
Logger.debug(TAG, "getSharedPreferences() finished at ${System.currentTimeMillis() - start}")
Logger.debug(
TAG,
"getSharedPreferences() finished at ${System.currentTimeMillis() - start}"
)
val secrets = Secrets("lanternMasterKey", secretsPreferences, oldSecretsPreferences)
Logger.debug(TAG, "Secrets() finished at ${System.currentTimeMillis() - start}")

Expand All @@ -67,14 +74,20 @@ abstract class BaseModel(
val dbPassword = try {
secrets.get(dbPasswordKey, dbPasswordLength)
} catch (e: InsecureSecretException) {
Logger.debug(TAG, "Old database password was stored insecurely, generate a new database password and prepare to copy data")
Logger.debug(
TAG,
"Old database password was stored insecurely, generate a new database password and prepare to copy data"
)
insecureDbPassword = e.secret
e.regenerate(dbPasswordLength)
}
masterDB = DB.createOrOpen(context, dbLocation, dbPassword)
dbPassword.clear()
insecureDbPassword?.let { insecurePassword ->
Logger.debug(TAG, "found old database encrypted with insecure password, migrate data to new secure database")
Logger.debug(
TAG,
"found old database encrypted with insecure password, migrate data to new secure database"
)
// What made the old password insecure is that it was stored as a String which
// tends to stick around for a long time in memory. We only ever used string
// passwords prior to the release of messaging, so nothing particularly sensitive
Expand Down Expand Up @@ -145,7 +158,7 @@ abstract class BaseModel(
errorDetails: Any?
) {
mainHandler.post {
mcResult.error(errorCode!!, errorMessage, errorDetails)
mcResult.error(errorCode!!, errorMessage, errorDetails)
}
}

Expand Down Expand Up @@ -180,14 +193,17 @@ abstract class BaseModel(
val path = call.arguments<String>()
db.getRaw<Any>(path!!)?.valueOrProtoBytes
}

"list" -> {
val path = call.argument<String>("path")
val start = call.argument<Int?>("start") ?: 0
val count = call.argument<Int?>("count") ?: Int.MAX_VALUE
val fullTextSearch = call.argument<String?>("fullTextSearch")
val reverseSort = call.argument<Boolean?>("reverseSort") ?: false
db.listRaw<Any>(path!!, start, count, reverseSort).map { it.value.valueOrProtoBytes }
db.listRaw<Any>(path!!, start, count, reverseSort)
.map { it.value.valueOrProtoBytes }
}

else -> notImplemented()
}
}
Expand All @@ -196,29 +212,35 @@ abstract class BaseModel(

@Synchronized
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
Logger.error(
TAG,
"Session Model onListen calling with argument ${arguments} with event ${events}"
);

activeSink.set(events)
val args = arguments as Map<String, Any>
val subscriberID = args["subscriberID"] as String
val path = args["path"] as String
val details = args["details"]?.let { it as Boolean } ?: false
activeSubscribers.add(subscriberID)

if (details) {
val subscriber: DetailsSubscriber<Any> = object : DetailsSubscriber<Any>(subscriberID, path) {
override fun onChanges(changes: DetailsChangeSet<Any>) {
mainHandler.post {
synchronized(this@BaseModel) {
activeSink.get()?.success(
mapOf(
"s" to subscriberID,
"u" to changes.updates.map { (path, value) -> path to value.value.valueOrProtoBytes }.toMap(),
"d" to changes.deletions.toList()
val subscriber: DetailsSubscriber<Any> =
object : DetailsSubscriber<Any>(subscriberID, path) {
override fun onChanges(changes: DetailsChangeSet<Any>) {
mainHandler.post {
synchronized(this@BaseModel) {
activeSink.get()?.success(
mapOf(
"s" to subscriberID,
"u" to changes.updates.map { (path, value) -> path to value.value.valueOrProtoBytes }
.toMap(),
"d" to changes.deletions.toList()
)
)
)
}
}
}
}
}
db.subscribe(subscriber)
} else {
val subscriber: RawSubscriber<Any> = object : RawSubscriber<Any>(subscriberID, path) {
Expand All @@ -228,7 +250,8 @@ abstract class BaseModel(
activeSink.get()?.success(
mapOf(
"s" to subscriberID,
"u" to changes.updates.map { (path, value) -> path to value.valueOrProtoBytes }.toMap(),
"u" to changes.updates.map { (path, value) -> path to value.valueOrProtoBytes }
.toMap(),
"d" to changes.deletions.toList()
)
)
Expand All @@ -241,6 +264,9 @@ abstract class BaseModel(
}

override fun onCancel(arguments: Any?) {
Logger.error(
TAG,
"Session Model onCancel calling with argument ${arguments} ")
if (arguments == null) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,11 @@ class MainActivity : FlutterActivity(), MethodChannel.MethodCallHandler,
private lateinit var notifications: NotificationHelper
private lateinit var receiver: NotificationReceiver
private var autoUpdateJob: Job? = null

private val lanternClient = LanternApp.getLanternHttpClient()

override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
val start = System.currentTimeMillis()
super.configureFlutterEngine(flutterEngine)

messagingModel = MessagingModel(this, flutterEngine)
vpnModel = VpnModel(this, flutterEngine, ::switchLantern)
sessionModel = SessionModel(this, flutterEngine)
Expand Down
Loading

0 comments on commit 37d1b35

Please sign in to comment.