Skip to content

Commit fac7a33

Browse files
authored
Merge pull request #4350 from owncloud/fix/clear_data_button_malfunctioning_hard_reset
[BUG] "Clear data" button malfunctioning
2 parents e1cf321 + 966a6a5 commit fac7a33

59 files changed

Lines changed: 77 additions & 438 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ownCloud admins and users.
2929

3030
## Summary
3131

32+
* Bugfix - "Clear data" button enabled in the app settings in device settings: [#4309](https://github.com/owncloud/android/issues/4309)
3233
* Bugfix - Remove lens icon in folder picker: [#4311](https://github.com/owncloud/android/issues/4311)
3334
* Bugfix - Retried successful uploads are cleaned up from the temporary folder: [#4335](https://github.com/owncloud/android/issues/4335)
3435
* Change - Upgrade minimum SDK version to Android 7.0 (v24): [#4230](https://github.com/owncloud/android/issues/4230)
@@ -44,6 +45,15 @@ ownCloud admins and users.
4445

4546
## Details
4647

48+
* Bugfix - "Clear data" button enabled in the app settings in device settings: [#4309](https://github.com/owncloud/android/issues/4309)
49+
50+
The "Clear data" button has been enabled to delete the application data from the
51+
app settings in the device settings. Shared preferences, temporary files,
52+
accounts and the local database will be cleared when the button is pressed.
53+
54+
https://github.com/owncloud/android/issues/4309
55+
https://github.com/owncloud/android/pull/4350
56+
4757
* Bugfix - Remove lens icon in folder picker: [#4311](https://github.com/owncloud/android/issues/4311)
4858

4959
The lens icon in the toolbar was removed only in the spaces screen.

changelog/unreleased/4350

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Bugfix: "Clear data" button enabled in the app settings in device settings
2+
3+
The "Clear data" button has been enabled to delete the application data from the app settings in the device settings.
4+
Shared preferences, temporary files, accounts and the local database will be cleared when the button is pressed.
5+
6+
https://github.com/owncloud/android/issues/4309
7+
https://github.com/owncloud/android/pull/4350

owncloudApp/src/main/AndroidManifest.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
android:icon="@mipmap/icon"
4949
android:label="@string/app_name"
5050
android:localeConfig="@xml/locales_config"
51-
android:manageSpaceActivity="com.owncloud.android.ui.activity.ManageSpaceActivity"
5251
android:networkSecurityConfig="@xml/network_security_config"
5352
android:preserveLegacyExternalStorage="true"
5453
android:requestLegacyExternalStorage="true"
@@ -211,10 +210,6 @@
211210
android:name="android.app.searchable"
212211
android:resource="@xml/users_and_groups_searchable" />
213212
</activity>
214-
<activity
215-
android:name=".ui.activity.ManageSpaceActivity"
216-
android:label="@string/manage_space_title"
217-
android:theme="@style/Theme.ownCloud" />
218213
<activity
219214
android:name=".presentation.security.pattern.PatternActivity"
220215
android:screenOrientation="portrait"

owncloudApp/src/main/java/com/owncloud/android/MainApp.kt

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
* @author Christian Schabesberger
88
* @author David Crespo Ríos
99
* @author Juan Carlos Garrote Gascón
10+
* @author Aitor Ballesteros Pavón
1011
*
11-
* Copyright (C) 2023 ownCloud GmbH.
12+
* Copyright (C) 2024 ownCloud GmbH.
1213
*
1314
* This program is free software: you can redistribute it and/or modify
1415
* it under the terms of the GNU General Public License version 2,
@@ -37,7 +38,6 @@ import android.view.WindowManager
3738
import android.widget.CheckBox
3839
import androidx.appcompat.app.AlertDialog
3940
import androidx.core.content.pm.PackageInfoCompat
40-
import com.owncloud.android.presentation.authentication.AccountUtils
4141
import com.owncloud.android.data.providers.implementation.OCSharedPreferencesProvider
4242
import com.owncloud.android.datamodel.ThumbnailsCacheManager
4343
import com.owncloud.android.db.PreferenceManager
@@ -52,19 +52,21 @@ import com.owncloud.android.domain.spaces.model.OCSpace
5252
import com.owncloud.android.domain.spaces.usecases.GetPersonalSpaceForAccountUseCase
5353
import com.owncloud.android.extensions.createNotificationChannel
5454
import com.owncloud.android.lib.common.SingleSessionManager
55+
import com.owncloud.android.presentation.authentication.AccountUtils
5556
import com.owncloud.android.presentation.migration.StorageMigrationActivity
5657
import com.owncloud.android.presentation.releasenotes.ReleaseNotesActivity
5758
import com.owncloud.android.presentation.security.biometric.BiometricActivity
5859
import com.owncloud.android.presentation.security.biometric.BiometricManager
59-
import com.owncloud.android.presentation.security.pattern.PatternActivity
60-
import com.owncloud.android.presentation.security.pattern.PatternManager
6160
import com.owncloud.android.presentation.security.passcode.PassCodeActivity
6261
import com.owncloud.android.presentation.security.passcode.PassCodeManager
62+
import com.owncloud.android.presentation.security.pattern.PatternActivity
63+
import com.owncloud.android.presentation.security.pattern.PatternManager
6364
import com.owncloud.android.presentation.settings.logging.SettingsLogsFragment.Companion.PREFERENCE_ENABLE_LOGGING
6465
import com.owncloud.android.providers.CoroutinesDispatcherProvider
6566
import com.owncloud.android.providers.LogsProvider
6667
import com.owncloud.android.providers.MdmProvider
6768
import com.owncloud.android.ui.activity.FileDisplayActivity
69+
import com.owncloud.android.ui.activity.FileDisplayActivity.Companion.PREFERENCE_CLEAR_DATA_ALREADY_TRIGGERED
6870
import com.owncloud.android.ui.activity.WhatsNewActivity
6971
import com.owncloud.android.utils.CONFIGURATION_ALLOW_SCREENSHOTS
7072
import com.owncloud.android.utils.DOWNLOAD_NOTIFICATION_CHANNEL_ID
@@ -133,24 +135,30 @@ class MainApp : Application() {
133135
ReleaseNotesActivity.runIfNeeded(activity)
134136

135137
val pref = PreferenceManager.getDefaultSharedPreferences(appContext)
136-
val dontShowAgainDialogPref = pref.getBoolean(PREFERENCE_KEY_DONT_SHOW_OCIS_ACCOUNT_WARNING_DIALOG, false)
137-
if (!dontShowAgainDialogPref && shouldShowDialog(activity)) {
138-
val checkboxDialog = activity.layoutInflater.inflate(R.layout.checkbox_dialog, null)
139-
val checkbox = checkboxDialog.findViewById<CheckBox>(R.id.checkbox_dialog)
140-
checkbox.setText(R.string.ocis_accounts_warning_checkbox_message)
141-
val builder = AlertDialog.Builder(activity).apply {
142-
setView(checkboxDialog)
143-
setTitle(R.string.ocis_accounts_warning_title)
144-
setMessage(R.string.ocis_accounts_warning_message)
145-
setCancelable(false)
146-
setPositiveButton(R.string.ocis_accounts_warning_button) { _, _ ->
147-
if (checkbox.isChecked) {
148-
pref.edit().putBoolean(PREFERENCE_KEY_DONT_SHOW_OCIS_ACCOUNT_WARNING_DIALOG, true).apply()
138+
val clearDataAlreadyTriggered = pref.contains(PREFERENCE_CLEAR_DATA_ALREADY_TRIGGERED)
139+
if (clearDataAlreadyTriggered || isNewVersionCode()) {
140+
val dontShowAgainDialogPref = pref.getBoolean(PREFERENCE_KEY_DONT_SHOW_OCIS_ACCOUNT_WARNING_DIALOG, false)
141+
if (!dontShowAgainDialogPref && shouldShowDialog(activity)) {
142+
val checkboxDialog = activity.layoutInflater.inflate(R.layout.checkbox_dialog, null)
143+
val checkbox = checkboxDialog.findViewById<CheckBox>(R.id.checkbox_dialog)
144+
checkbox.setText(R.string.ocis_accounts_warning_checkbox_message)
145+
val builder = AlertDialog.Builder(activity).apply {
146+
setView(checkboxDialog)
147+
setTitle(R.string.ocis_accounts_warning_title)
148+
setMessage(R.string.ocis_accounts_warning_message)
149+
setCancelable(false)
150+
setPositiveButton(R.string.ocis_accounts_warning_button) { _, _ ->
151+
if (checkbox.isChecked) {
152+
pref.edit().putBoolean(PREFERENCE_KEY_DONT_SHOW_OCIS_ACCOUNT_WARNING_DIALOG, true).apply()
153+
}
149154
}
150155
}
156+
val alertDialog = builder.create()
157+
alertDialog.show()
151158
}
152-
val alertDialog = builder.create()
153-
alertDialog.show()
159+
} else { // "Clear data" button is pressed from the app settings in the device settings.
160+
AccountUtils.deleteAccounts(appContext)
161+
WhatsNewActivity.runIfNeeded(activity)
154162
}
155163
}
156164
}
@@ -381,5 +389,13 @@ class MainApp : Application() {
381389
val pref = PreferenceManager.getDefaultSharedPreferences(appContext)
382390
return pref.getInt(PREFERENCE_KEY_LAST_SEEN_VERSION_CODE, 0)
383391
}
392+
393+
private fun isNewVersionCode(): Boolean {
394+
val lastSeenVersionCode = getLastSeenVersionCode()
395+
if (lastSeenVersionCode == 0) { // The preferences have been deleted, so we can delete the accounts and navigate to login
396+
return false
397+
}
398+
return lastSeenVersionCode != versionCode // The version has changed and the accounts must not be deleted
399+
}
384400
}
385401
}

owncloudApp/src/main/java/com/owncloud/android/presentation/authentication/AccountUtils.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/**
22
* ownCloud Android client application
33
* <p>
4+
* @author Aitor Ballesteros Pavón
5+
* <p>
46
* Copyright (C) 2012 Bartek Przybylski
5-
* Copyright (C) 2020 ownCloud GmbH.
7+
* Copyright (C) 2024 ownCloud GmbH.
68
* <p>
79
* This program is free software: you can redistribute it and/or modify
810
* it under the terms of the GNU General Public License version 2,
@@ -81,6 +83,14 @@ public static Account[] getAccounts(Context context) {
8183
return accountManager.getAccountsByType(MainApp.Companion.getAccountType());
8284
}
8385

86+
public static void deleteAccounts(Context context) {
87+
AccountManager accountManager = AccountManager.get(context);
88+
Account[] accounts = getAccounts(context);
89+
for (Account account : accounts) {
90+
accountManager.removeAccount(account, null, null, null);
91+
}
92+
}
93+
8494
public static boolean exists(String accountName, Context context) {
8595
Account[] ocAccounts = getAccounts(context);
8696

owncloudApp/src/main/java/com/owncloud/android/presentation/releasenotes/ReleaseNotesViewModel.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class ReleaseNotesViewModel(
9090
subtitle = R.string.release_notes_4_3_0_subtitle_manual_removal_local_storage,
9191
type = ReleaseNoteType.ENHANCEMENT,
9292
),
93+
ReleaseNote(
94+
title = R.string.release_notes_4_3_0_title_clear_data_button_hard_reset,
95+
subtitle = R.string.release_notes_4_3_0_subtitle_clear_data_button_hard_reset,
96+
type = ReleaseNoteType.BUGFIX,
97+
),
9398
)
9499
}
95100
}

owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
* @author Shashvat Kedia
99
* @author Abel García de Prada
1010
* @author Juan Carlos Garrote Gascón
11+
* @author Aitor Ballesteros Pavón
1112
*
1213
* Copyright (C) 2011 Bartek Przybylski
13-
* Copyright (C) 2023 ownCloud GmbH.
14+
* Copyright (C) 2024 ownCloud GmbH.
1415
*
1516
* This program is free software: you can redistribute it and/or modify
1617
* it under the terms of the GNU General Public License version 2,
@@ -188,6 +189,10 @@ class FileDisplayActivity : FileActivity(),
188189

189190
checkPasscodeEnforced(this)
190191

192+
if (BuildConfig.DEBUG) {
193+
sharedPreferences.putInt(MainApp.PREFERENCE_KEY_LAST_SEEN_VERSION_CODE, MainApp.versionCode)
194+
}
195+
sharedPreferences.putBoolean(PREFERENCE_CLEAR_DATA_ALREADY_TRIGGERED, true)
191196
localBroadcastManager = LocalBroadcastManager.getInstance(this)
192197

193198
handleDeepLink()
@@ -1868,6 +1873,7 @@ class FileDisplayActivity : FileActivity(),
18681873
private const val CUSTOM_DIALOG_TAG = "CUSTOM_DIALOG"
18691874

18701875
private const val PREFERENCE_NOTIFICATION_PERMISSION_REQUESTED = "PREFERENCE_NOTIFICATION_PERMISSION_REQUESTED"
1876+
const val PREFERENCE_CLEAR_DATA_ALREADY_TRIGGERED = "PREFERENCE_CLEAR_DATA_ALREADY_TRIGGERED"
18711877
const val ALL_FILES_SAF_REGEX = "*/*"
18721878

18731879
const val ACTION_DETAILS = "com.owncloud.android.ui.activity.action.DETAILS"

0 commit comments

Comments
 (0)