2022-08-19 19:53:40 +00:00
|
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
2022-05-03 20:29:00 +00:00
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
2021-08-23 14:15:01 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2020-10-30 18:31:04 +00:00
|
|
|
|
|
|
|
import * as List from '../containers/List';
|
2022-05-03 20:29:00 +00:00
|
|
|
import SafeAreaView from '../containers/SafeAreaView';
|
|
|
|
import StatusBar from '../containers/StatusBar';
|
2020-10-30 18:31:04 +00:00
|
|
|
import I18n from '../i18n';
|
2024-04-18 10:19:54 +00:00
|
|
|
import { ANALYTICS_EVENTS_KEY, CRASH_REPORT_KEY, isFDroidBuild } from '../lib/constants';
|
2022-05-13 15:01:34 +00:00
|
|
|
import { useAppSelector } from '../lib/hooks';
|
2022-05-03 20:29:00 +00:00
|
|
|
import useServer from '../lib/methods/useServer';
|
|
|
|
import { SettingsStackParamList } from '../stacks/types';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { handleLocalAuthentication } from '../lib/methods/helpers/localAuthentication';
|
2020-10-30 18:31:04 +00:00
|
|
|
import {
|
2021-09-13 20:41:05 +00:00
|
|
|
events,
|
2022-05-03 20:29:00 +00:00
|
|
|
getReportAnalyticsEventsValue,
|
2021-09-13 20:41:05 +00:00
|
|
|
getReportCrashErrorsValue,
|
2022-05-03 20:29:00 +00:00
|
|
|
logEvent,
|
|
|
|
toggleAnalyticsEventsReport,
|
|
|
|
toggleCrashErrorsReport
|
2022-06-06 14:17:51 +00:00
|
|
|
} from '../lib/methods/helpers/log';
|
2024-04-18 10:19:54 +00:00
|
|
|
import Switch from '../containers/Switch';
|
2020-10-30 18:31:04 +00:00
|
|
|
|
2021-12-02 13:26:34 +00:00
|
|
|
interface ISecurityPrivacyViewProps {
|
2022-05-03 02:06:37 +00:00
|
|
|
navigation: StackNavigationProp<SettingsStackParamList, 'SecurityPrivacyView'>;
|
2021-12-02 13:26:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const SecurityPrivacyView = ({ navigation }: ISecurityPrivacyViewProps): JSX.Element => {
|
2021-08-23 14:15:01 +00:00
|
|
|
const [crashReportState, setCrashReportState] = useState(getReportCrashErrorsValue());
|
|
|
|
const [analyticsEventsState, setAnalyticsEventsState] = useState(getReportAnalyticsEventsValue());
|
2022-05-03 20:29:00 +00:00
|
|
|
const [server] = useServer();
|
2020-10-30 18:31:04 +00:00
|
|
|
|
2022-05-13 15:01:34 +00:00
|
|
|
const e2eEnabled = useAppSelector(state => state.settings.E2E_Enable);
|
2020-10-30 18:31:04 +00:00
|
|
|
|
2021-08-23 14:15:01 +00:00
|
|
|
useEffect(() => {
|
|
|
|
navigation.setOptions({
|
|
|
|
title: I18n.t('Security_and_privacy')
|
|
|
|
});
|
2022-05-03 02:06:37 +00:00
|
|
|
}, [navigation]);
|
2021-08-23 14:15:01 +00:00
|
|
|
|
2021-12-02 13:26:34 +00:00
|
|
|
const toggleCrashReport = (value: boolean) => {
|
|
|
|
logEvent(events.SP_TOGGLE_CRASH_REPORT);
|
2020-10-30 18:31:04 +00:00
|
|
|
AsyncStorage.setItem(CRASH_REPORT_KEY, JSON.stringify(value));
|
2021-08-23 14:15:01 +00:00
|
|
|
setCrashReportState(value);
|
|
|
|
toggleCrashErrorsReport(value);
|
|
|
|
};
|
2020-10-30 18:31:04 +00:00
|
|
|
|
2021-12-02 13:26:34 +00:00
|
|
|
const toggleAnalyticsEvents = (value: boolean) => {
|
|
|
|
logEvent(events.SP_TOGGLE_ANALYTICS_EVENTS);
|
2020-10-30 18:31:04 +00:00
|
|
|
AsyncStorage.setItem(ANALYTICS_EVENTS_KEY, JSON.stringify(value));
|
2021-08-23 14:15:01 +00:00
|
|
|
setAnalyticsEventsState(value);
|
|
|
|
toggleAnalyticsEventsReport(value);
|
|
|
|
};
|
2020-10-30 18:31:04 +00:00
|
|
|
|
2021-12-02 13:26:34 +00:00
|
|
|
const navigateToScreen = (screen: 'E2EEncryptionSecurityView' | 'ScreenLockConfigView') => {
|
|
|
|
// @ts-ignore
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events[`SP_GO_${screen.replace('View', '').toUpperCase()}`]);
|
2020-10-30 18:31:04 +00:00
|
|
|
navigation.navigate(screen);
|
2021-08-23 14:15:01 +00:00
|
|
|
};
|
2020-10-30 18:31:04 +00:00
|
|
|
|
2022-05-03 20:29:00 +00:00
|
|
|
const navigateToScreenLockConfigView = async () => {
|
|
|
|
if (server?.autoLock) {
|
|
|
|
await handleLocalAuthentication(true);
|
|
|
|
}
|
|
|
|
navigateToScreen('ScreenLockConfigView');
|
|
|
|
};
|
|
|
|
|
2021-08-23 14:15:01 +00:00
|
|
|
return (
|
|
|
|
<SafeAreaView testID='security-privacy-view'>
|
|
|
|
<StatusBar />
|
|
|
|
<List.Container testID='security-privacy-view-list'>
|
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
2021-09-13 20:41:05 +00:00
|
|
|
{e2eEnabled ? (
|
|
|
|
<>
|
|
|
|
<List.Item
|
|
|
|
title='E2E_Encryption'
|
|
|
|
showActionIndicator
|
|
|
|
onPress={() => navigateToScreen('E2EEncryptionSecurityView')}
|
|
|
|
testID='security-privacy-view-e2e-encryption'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</>
|
|
|
|
) : null}
|
2021-08-23 14:15:01 +00:00
|
|
|
<List.Item
|
|
|
|
title='Screen_lock'
|
|
|
|
showActionIndicator
|
2022-05-03 20:29:00 +00:00
|
|
|
onPress={navigateToScreenLockConfigView}
|
2021-08-23 14:15:01 +00:00
|
|
|
testID='security-privacy-view-screen-lock'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
2020-10-30 18:31:04 +00:00
|
|
|
|
2021-08-23 14:15:01 +00:00
|
|
|
{!isFDroidBuild ? (
|
|
|
|
<>
|
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Log_analytics_events'
|
|
|
|
testID='security-privacy-view-analytics-events'
|
|
|
|
right={() => (
|
2024-04-18 10:19:54 +00:00
|
|
|
<Switch value={analyticsEventsState} onValueChange={toggleAnalyticsEvents} />
|
2021-08-23 14:15:01 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Send_crash_report'
|
|
|
|
testID='security-privacy-view-crash-report'
|
|
|
|
right={() => (
|
2024-04-18 10:19:54 +00:00
|
|
|
<Switch value={crashReportState} onValueChange={toggleCrashReport} />
|
2021-08-23 14:15:01 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Info info='Crash_report_disclaimer' />
|
|
|
|
</List.Section>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
</List.Container>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
};
|
2020-10-30 18:31:04 +00:00
|
|
|
|
2021-08-23 14:15:01 +00:00
|
|
|
export default SecurityPrivacyView;
|