2022-05-03 20:29:00 +00:00
|
|
|
import AsyncStorage from '@react-native-community/async-storage';
|
|
|
|
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 { Switch } from 'react-native';
|
|
|
|
|
|
|
|
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';
|
2022-05-03 20:29:00 +00:00
|
|
|
import { ANALYTICS_EVENTS_KEY, CRASH_REPORT_KEY, isFDroidBuild, SWITCH_TRACK_COLOR } 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';
|
|
|
|
import { handleLocalAuthentication } from '../utils/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
|
2020-10-30 18:31:04 +00:00
|
|
|
} from '../utils/log';
|
|
|
|
|
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={() => (
|
2021-09-13 20:41:05 +00:00
|
|
|
<Switch value={analyticsEventsState} trackColor={SWITCH_TRACK_COLOR} 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={() => (
|
2021-09-13 20:41:05 +00:00
|
|
|
<Switch value={crashReportState} trackColor={SWITCH_TRACK_COLOR} 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;
|