Merge pull request 'Initial Implementation of #522' (#721) from stable-blockers into trunk
continuous-integration/drone/push Build is pending Details

Reviewed-on: #721
Reviewed-by: Dan Ballard <dan@openprivacy.ca>
This commit is contained in:
Sarah Jamie Lewis 2023-09-11 21:53:41 +00:00
commit 70a7b338b2
5 changed files with 81 additions and 5 deletions

View File

@ -29,7 +29,7 @@ import org.json.JSONObject
import java.nio.file.Files
import java.nio.file.Paths
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.*
class MainActivity: FlutterActivity() {
override fun provideSplashScreen(): SplashScreen? = SplashView()
@ -38,6 +38,7 @@ class MainActivity: FlutterActivity() {
// Channel to get app info
private val CHANNEL_APP_INFO = "test.flutter.dev/applicationInfo"
private val CALL_APP_INFO = "getNativeLibDir"
private val CALL_SERVICE_INFO = "getForegroundServiceInfo"
private val ANDROID_SETTINGS_CHANNEL_NAME = "androidSettings"
private val ANDROID_SETTINGS_CHANGE_NAME= "androidSettingsChanged"
private var andoidSettingsChangeChannel: MethodChannel? = null
@ -189,7 +190,9 @@ class MainActivity: FlutterActivity() {
when (call.method) {
CALL_APP_INFO -> result.success(getNativeLibDir())
?: result.error("Unavailable", "nativeLibDir not available", null);
else -> result.notImplemented()
CALL_SERVICE_INFO -> result.success(getForegroundServiceInfo())
?: result.error("Unavailable", "getForegroundServiceInfo not available", null);
else -> result.notImplemented()
}
}
@ -224,6 +227,24 @@ class MainActivity: FlutterActivity() {
return ainfo.nativeLibraryDir
}
fun getForegroundServiceInfo(): HashMap<String,String> {
var hashMap : HashMap<String, String>
= HashMap<String, String> ();
val workmanager = WorkManager.getInstance(this);
if (workmanager != null) {
runBlocking {
var lastCancelAllTime = workmanager.getLastCancelAllTimeMillis().await();
hashMap.put("workmanager.lastCancelAllTime", lastCancelAllTime.toString());
}
val works = workmanager.getWorkInfosByTag(WORKER_TAG).get()
for (workInfo in works) {
hashMap.put("workmanager.${workInfo.id}.state", workInfo.state.toString());
}
}
return hashMap
}
// receives messages from the ForegroundService (which provides, ironically enough, the backend)
private fun handleCwtch(@NonNull call: MethodCall, @NonNull result: Result) {
var method = call.method

View File

@ -1,10 +1,14 @@
// To handle profiles that are "unencrypted" (i.e don't require a password to open) we currently create a profile with a defacto, hardcoded password.
// Details: https://docs.openprivacy.ca/cwtch-security-handbook/profile_encryption_and_storage.html
import 'dart:collection';
const DefaultPassword = "be gay do crime";
const LastMessageSeenTimeKey = "profile.lastMessageSeenTime";
abstract class Cwtch {
Future<HashMap<String, String>> PlatformChannelInfo();
// ignore: non_constant_identifier_names
Future<void> Start();
// ignore: non_constant_identifier_names

View File

@ -1,3 +1,4 @@
import 'dart:collection';
import 'dart:convert';
import 'dart:ffi';
import 'dart:io';
@ -1055,4 +1056,9 @@ class CwtchFfi implements Cwtch {
malloc.free(utf8pattern);
return searchID;
}
@override
Future<HashMap<String, String>> PlatformChannelInfo() {
return Future.value(HashMap<String, String>());
}
}

View File

@ -1,3 +1,4 @@
import 'dart:collection';
import 'dart:convert';
import 'package:cwtch/config.dart';
@ -32,6 +33,23 @@ class CwtchGomobile implements Cwtch {
late CwtchNotifier cwtchNotifier;
bool _isL10nInit = false;
@override
Future<HashMap<String, String>> PlatformChannelInfo() async {
HashMap<String, String> info = HashMap<String, String>();
info.addAll({"appInfoPlatform.name": appInfoPlatform.name});
info.addAll({"appInfoPlatform.codec": appInfoPlatform.codec.toString()});
EnvironmentConfig.debugLog("getting foreground service info...");
appInfoPlatform.invokeMapMethod('getForegroundServiceInfo').then((foregroundServiceInfoMap) {
EnvironmentConfig.debugLog("parsing foreground service info...");
foregroundServiceInfoMap?.entries.forEach((element) {
info.addAll({element.key.toString(): element.value.toString()});
});
});
EnvironmentConfig.debugLog("returning foreground service info...");
return info;
}
CwtchGomobile(CwtchNotifier _cwtchNotifier) {
print("gomobile.dart: CwtchGomobile()");
cwtchNotifier = _cwtchNotifier;

View File

@ -1,6 +1,6 @@
import 'dart:collection';
import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'package:cwtch/cwtch_icons_icons.dart';
import 'package:cwtch/models/servers.dart';
import 'package:cwtch/themes/juniper.dart';
@ -366,7 +366,7 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
},
activeTrackColor: settings.theme.defaultButtonColor,
inactiveTrackColor: settings.theme.defaultButtonDisabledColor,
secondary: Icon(CwtchIcons.block_unknown, color: settings.current().mainTextColor),
secondary: Icon(CwtchIcons.peer_history, color: settings.current().mainTextColor),
),
SizedBox(
height: 40,
@ -635,7 +635,18 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
}
},
),
)
),
Visibility(
visible: EnvironmentConfig.BUILD_VER == dev_version,
child: FutureBuilder(
future: Provider.of<FlwtchState>(context).cwtch.PlatformChannelInfo(),
builder: (context, snapshot) {
if (snapshot.hasData) {
HashMap<String, String> data = snapshot.data as HashMap<String, String>;
return getPlatformInfo(settings, data);
}
return Container();
}))
]))));
});
});
@ -665,6 +676,22 @@ class _GlobalSettingsViewState extends State<GlobalSettingsView> {
},
);
}
getPlatformInfo(settings, HashMap<String, String> platformChannelInfo) {
var sortedKeys = platformChannelInfo.keys.toList();
sortedKeys.sort();
var widgets = List<Widget>.empty(growable: true);
sortedKeys.forEach((element) {
widgets.add(ListTile(
leading: Icon(Icons.android, color: settings.current().mainTextColor),
title: Text(element),
subtitle: Text(platformChannelInfo[element]!),
));
});
return Column(
children: widgets,
);
}
}
bool checkDownloadDirectory(context, settings) {