5454import com .nextcloud .client .preferences .DarkMode ;
5555import com .nextcloud .utils .extensions .ContextExtensionsKt ;
5656import com .nextcloud .utils .mdm .MDMConfig ;
57+ import com .owncloud .android .BuildConfig ;
5758import com .owncloud .android .MainApp ;
5859import com .owncloud .android .R ;
5960import com .owncloud .android .authentication .AuthenticatorActivity ;
6364import com .owncloud .android .lib .common .ExternalLink ;
6465import com .owncloud .android .lib .common .ExternalLinkType ;
6566import com .owncloud .android .lib .common .utils .Log_OC ;
67+ import com .owncloud .android .operations .e2e .E2EDeletionService ;
6668import com .owncloud .android .providers .DocumentsStorageProvider ;
6769import com .owncloud .android .ui .ThemeableSwitchPreference ;
6870import com .owncloud .android .ui .asynctasks .LoadingVersionNumberTask ;
7880import com .owncloud .android .utils .theme .CapabilityUtils ;
7981import com .owncloud .android .utils .theme .ViewThemeUtils ;
8082
81- import java .util .List ;
8283import java .util .Objects ;
8384
8485import javax .inject .Inject ;
9192import androidx .core .content .ContextCompat ;
9293import androidx .core .content .res .ResourcesCompat ;
9394import kotlin .Unit ;
94- import kotlin .jvm .functions .Function1 ;
9595
9696import static com .owncloud .android .ui .activity .DrawerActivity .REQ_ALL_FILES_ACCESS ;
9797
@@ -138,6 +138,8 @@ public class SettingsActivity extends PreferenceActivity
138138 private String storagePath ;
139139 private String pendingLock ;
140140
141+ private E2EDeletionService e2EDeletionService ;
142+
141143 private User user ;
142144 @ Inject ArbitraryDataProvider arbitraryDataProvider ;
143145 @ Inject AppPreferences preferences ;
@@ -164,6 +166,7 @@ public void onCreate(Bundle savedInstanceState) {
164166 PreferenceScreen preferenceScreen = (PreferenceScreen ) findPreference ("preference_screen" );
165167
166168 user = accountManager .getUser ();
169+ e2EDeletionService = new E2EDeletionService (clientFactory );
167170
168171 // retrieve user's base uri
169172 setupBaseUri ();
@@ -368,6 +371,8 @@ private void setupMoreCategory() {
368371
369372 removeE2E (preferenceCategoryMore );
370373
374+ removeE2EFilesAndKeys (preferenceCategoryMore );
375+
371376 setupHelpPreference (preferenceCategoryMore );
372377
373378 setupRecommendPreference (preferenceCategoryMore );
@@ -537,6 +542,46 @@ private void removeE2E(PreferenceCategory preferenceCategoryMore) {
537542 }
538543 }
539544
545+ private void removeE2EFilesAndKeys (PreferenceCategory preferenceCategoryMore ) {
546+ if (BuildConfig .DEBUG ) {
547+ Preference removeKeysAndFilesPreference = findPreference ("remove_e2e_files_and_keys" );
548+ if (removeKeysAndFilesPreference != null ) {
549+ if (!FileOperationsHelper .isEndToEndEncryptionSetup (this , user )) {
550+ preferenceCategoryMore .removePreference (removeKeysAndFilesPreference );
551+ } else {
552+ removeKeysAndFilesPreference .setOnPreferenceClickListener (p -> {
553+ showRemoveE2EKeysAndFilesAlertDialog (preferenceCategoryMore , removeKeysAndFilesPreference );
554+ return true ;
555+ });
556+ }
557+ }
558+ }
559+ }
560+
561+ private void showRemoveE2EKeysAndFilesAlertDialog (PreferenceCategory preferenceCategoryMore , Preference preference ) {
562+ if (e2EDeletionService == null ) {
563+ return ;
564+ }
565+
566+ e2EDeletionService .showRemoveE2EKeysAndFilesAlertDialog (this , user , success -> {
567+ if (success ) {
568+ EncryptionUtils .removeE2E (arbitraryDataProvider , user );
569+ preferenceCategoryMore .removePreference (preference );
570+
571+ Preference pMnemonic = findPreference ("mnemonic" );
572+ if (pMnemonic != null ) {
573+ preferenceCategoryMore .removePreference (pMnemonic );
574+ }
575+
576+ Preference pRemoveE2E = findPreference ("remove_e2e" );
577+ if (pRemoveE2E != null ) {
578+ preferenceCategoryMore .removePreference (pRemoveE2E );
579+ }
580+ }
581+ return Unit .INSTANCE ;
582+ });
583+ }
584+
540585 private void showRemoveE2EAlertDialog (PreferenceCategory preferenceCategoryMore , Preference preference ) {
541586 new MaterialAlertDialogBuilder (this , R .style .FallbackTheming_Dialog )
542587 .setTitle (R .string .prefs_e2e_mnemonic )
0 commit comments