Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experiment] Obfuscate App Access #1972

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/lib/features/labs/model/labs_features.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum LabsFeature {
// specific features
chatUnread,
chatNG,
obfuscatedApp,

// system features
deviceCalendarSync,
Expand Down
17 changes: 17 additions & 0 deletions app/lib/features/settings/pages/labs_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class SettingsLabsPage extends ConsumerWidget {
title: Text(lang.labsAppFeatures),
tiles: [
const LabsNotificationsSettingsTile(),
],
),
SettingsSection(
title: Text(lang.securityAndPrivacy),
tiles: [
SettingsTile.switchTile(
title: Text(lang.encryptionBackupKeyBackup),
description: Text(lang.sharedCalendarAndEvents),
Expand All @@ -44,6 +49,18 @@ class SettingsLabsPage extends ConsumerWidget {
newVal,
),
),
SettingsTile.switchTile(
title: const Text('Hide App behind Calculator'),
description: const Text(
'Show a calculator when starting or switching to the app. Press 1984 enter to pass'),
initialValue:
ref.watch(isActiveProvider(LabsFeature.obfuscatedApp)),
onToggle: (newVal) => updateFeatureState(
ref,
LabsFeature.obfuscatedApp,
newVal,
),
),
],
),
SettingsSection(
Expand Down
89 changes: 80 additions & 9 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import 'dart:async';

import 'package:acter/common/themes/app_theme.dart';
import 'package:acter/config/desktop.dart';
import 'package:acter/config/env.g.dart';
import 'package:acter/config/notifications/init.dart';
import 'package:acter/common/providers/app_state_provider.dart';
import 'package:acter/common/themes/acter_theme.dart';
import 'package:acter/common/themes/app_theme.dart';
import 'package:acter/common/tutorial_dialogs/bottom_navigation_tutorials/bottom_navigation_tutorials.dart';
import 'package:acter/common/tutorial_dialogs/space_overview_tutorials/create_or_join_space_tutorials.dart';
import 'package:acter/common/tutorial_dialogs/space_overview_tutorials/space_overview_tutorials.dart';
import 'package:acter/common/utils/logging.dart';
import 'package:acter/common/utils/main.dart';
import 'package:acter/config/desktop.dart';
import 'package:acter/config/env.g.dart';
import 'package:acter/config/notifications/init.dart';
import 'package:acter/config/setup.dart';
import 'package:acter/features/cli/main.dart';
import 'package:acter/features/labs/model/labs_features.dart';
import 'package:acter/features/labs/providers/labs_providers.dart';
import 'package:acter/features/settings/providers/settings_providers.dart';
import 'package:acter/router/router.dart';
import 'package:flutter/cupertino.dart';
import 'package:acter_trigger_auto_complete/acter_trigger_autocomplete.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_simple_calculator/flutter_simple_calculator.dart';
import 'package:secure_application/secure_application.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:video_player_media_kit/video_player_media_kit.dart';
Expand Down Expand Up @@ -96,11 +101,19 @@ class Acter extends ConsumerStatefulWidget {
}

class _ActerState extends ConsumerState<Acter> with WidgetsBindingObserver {
final secureApplicationController = SecureApplicationController(
SecureApplicationState(
locked: true,
secured: true,
),
);
@override
void initState() {
super.initState();
ref.read(localeProvider.notifier).initLanguage();
WidgetsBinding.instance.addObserver(this);

// WidgetsBinding.instance?.addPostFrameCallback((_) => localAuthenticate());
}

@override
Expand All @@ -114,21 +127,79 @@ class _ActerState extends ConsumerState<Acter> with WidgetsBindingObserver {
super.dispose();
}

@override
Widget build(BuildContext context) {
final language = ref.watch(localeProvider);
Widget appBuilder(BuildContext context, Widget? child) {
final obfuscateApp = ref.watch(isActiveProvider(LabsFeature.obfuscatedApp));

// EasyLoading Wrapper
final easyLoadingBuilder = EasyLoading.init();
// all toast msgs will appear at bottom
final builder = EasyLoading.init();
EasyLoading.instance.toastPosition = EasyLoadingToastPosition.bottom;
final inner = easyLoadingBuilder(context, child);

if (obfuscateApp) {
return SecureApplication(
nativeRemoveDelay: 800,
secureApplicationController: secureApplicationController,
child: SecureGate(
opacity: 1,
lockedBuilder: (context, secureNotifier) => SimpleCalculator(
onChanged: (key, value, expression) {
print("key $key, value $value, expression: $expression");
if (value.toString() == '1984.0') {
secureNotifier!.unlock();
}
},
),
child: inner,
),
);
}

return inner;
}

Future<bool?> askValidation(BuildContext context) async {
final context = rootNavKey.currentState!.overlay!.context;
print("asking to validate!");
return await showDialog<bool>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text('Unlock app content'),
content: Text(
'Do you wan to unlock the application content? Clicking no will secure the app'),
actions: <Widget>[
CupertinoDialogAction(
isDefaultAction: true,
child: Text('No'),
onPressed: () {
Navigator.of(context).pop(false);
},
),
CupertinoDialogAction(
child: Text('Yes'),
onPressed: () {
Navigator.of(context).pop(true);
},
),
],
);
},
);
}

@override
Widget build(BuildContext context) {
final language = ref.watch(localeProvider);

return Portal(
child: MaterialApp.router(
routerConfig: goRouter,
theme: ActerTheme.theme,
restorationScopeId: 'acter',
title: 'Acter',
builder: builder,
builder: appBuilder,
locale: Locale(language),
localizationsDelegates: L10n.localizationsDelegates,
supportedLocales: L10n.supportedLocales,
Expand Down
Loading
Loading