Skip to content

Commit 7ff8105

Browse files
📝 Add docstrings to feature/freemium
Docstrings generation was requested by @tobihagemann. * #630 (comment) The following files were modified: * `data/src/main/java/org/cryptomator/data/db/DatabaseUpgrades.java` * `data/src/main/java/org/cryptomator/data/db/Upgrade13To14.kt` * `data/src/main/java/org/cryptomator/data/db/entities/UpdateCheckEntity.java` * `data/src/main/java/org/cryptomator/data/repository/HubRepositoryImpl.java` * `data/src/main/java/org/cryptomator/data/repository/UpdateCheckRepositoryImpl.java` * `domain/src/main/java/org/cryptomator/domain/Vault.java` * `domain/src/main/java/org/cryptomator/domain/repository/HubRepository.kt` * `domain/src/main/java/org/cryptomator/domain/repository/UpdateCheckRepository.java` * `domain/src/main/java/org/cryptomator/domain/usecases/DoLicenseCheck.java` * `domain/src/main/java/org/cryptomator/domain/usecases/vault/UnlockHubVault.java` * `presentation/src/main/java/org/cryptomator/presentation/CryptomatorApp.kt` * `presentation/src/main/java/org/cryptomator/presentation/di/component/ActivityComponent.java` * `presentation/src/main/java/org/cryptomator/presentation/intent/LicenseCheckIntent.java` * `presentation/src/main/java/org/cryptomator/presentation/intent/TextEditorIntent.java` * `presentation/src/main/java/org/cryptomator/presentation/licensing/LicenseEnforcer.kt` * `presentation/src/main/java/org/cryptomator/presentation/licensing/LicenseStateOrchestrator.kt` * `presentation/src/main/java/org/cryptomator/presentation/presenter/BaseLicensePresenter.kt` * `presentation/src/main/java/org/cryptomator/presentation/presenter/BrowseFilesPresenter.kt` * `presentation/src/main/java/org/cryptomator/presentation/presenter/ChooseCloudServicePresenter.kt` * `presentation/src/main/java/org/cryptomator/presentation/presenter/CloudSettingsPresenter.kt` * `presentation/src/main/java/org/cryptomator/presentation/presenter/SettingsPresenter.kt` * `presentation/src/main/java/org/cryptomator/presentation/presenter/SharedFilesPresenter.kt` * `presentation/src/main/java/org/cryptomator/presentation/presenter/VaultListPresenter.kt` * `presentation/src/main/java/org/cryptomator/presentation/presenter/WelcomePresenter.kt` * `presentation/src/main/java/org/cryptomator/presentation/service/ProductInfo.kt` * `presentation/src/main/java/org/cryptomator/presentation/service/PurchaseRevokedReason.kt` * `presentation/src/main/java/org/cryptomator/presentation/service/PurchaseRevokedToastObserver.kt` * `presentation/src/main/java/org/cryptomator/presentation/service/RestoreOutcomeHandler.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/activity/BrowseFilesActivity.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/activity/LicenseCheckActivity.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/activity/SharedFilesActivity.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/activity/TextEditorActivity.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/activity/VaultListActivity.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/activity/WelcomeActivity.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/activity/view/SharedFilesView.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/activity/view/UpdateLicenseView.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/activity/view/WelcomeView.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/dialog/NoFullVersionDialog.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/dialog/RestoreFailedDialog.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/dialog/RestoreSuccessfulDialog.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/dialog/TrialExpiredDialog.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/fragment/SettingsFragment.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/fragment/SharedFilesFragment.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/fragment/TextEditorFragment.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/fragment/WelcomeIntroFragment.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/fragment/WelcomeLicenseFragment.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/fragment/WelcomeNotificationsFragment.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/fragment/WelcomeScreenLockFragment.kt` * `presentation/src/main/java/org/cryptomator/presentation/ui/layout/LicenseContentViewBinder.kt` * `presentation/src/nonplaystoreiap/java/org/cryptomator/presentation/service/IapBillingService.kt` * `presentation/src/playstoreiap/java/org/cryptomator/presentation/service/IapBillingService.kt` * `presentation/src/playstoreiap/java/org/cryptomator/presentation/service/PurchaseManager.kt` * `presentation/src/playstoreiap/java/org/cryptomator/presentation/service/PurchaseRefreshCoordinator.kt` * `util/src/main/java/org/cryptomator/util/SharedPreferencesHandler.kt`
1 parent d4969ae commit 7ff8105

54 files changed

Lines changed: 1983 additions & 64 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.

data/src/main/java/org/cryptomator/data/db/DatabaseUpgrades.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,28 @@ class DatabaseUpgrades {
1717

1818
private final Map<Integer, List<DatabaseUpgrade>> availableUpgrades;
1919

20+
/**
21+
* Creates the DatabaseUpgrades registry and registers the provided upgrade steps
22+
* into the internal mapping keyed by each step's source version.
23+
*
24+
* Each constructor parameter is the implementation for the corresponding
25+
* from->to version and will be added to the availableUpgrades map.
26+
*
27+
* @param upgrade0To1 upgrade step from version 0 to 1
28+
* @param upgrade1To2 upgrade step from version 1 to 2
29+
* @param upgrade2To3 upgrade step from version 2 to 3
30+
* @param upgrade3To4 upgrade step from version 3 to 4
31+
* @param upgrade4To5 upgrade step from version 4 to 5
32+
* @param upgrade5To6 upgrade step from version 5 to 6
33+
* @param upgrade6To7 upgrade step from version 6 to 7
34+
* @param upgrade7To8 upgrade step from version 7 to 8
35+
* @param upgrade8To9 upgrade step from version 8 to 9
36+
* @param upgrade9To10 upgrade step from version 9 to 10
37+
* @param upgrade10To11 upgrade step from version 10 to 11
38+
* @param upgrade11To12 upgrade step from version 11 to 12
39+
* @param upgrade12To13 upgrade step from version 12 to 13
40+
* @param upgrade13To14 upgrade step from version 13 to 14
41+
*/
2042
@Inject
2143
public DatabaseUpgrades( //
2244
Upgrade0To1 upgrade0To1, //
@@ -52,6 +74,12 @@ public DatabaseUpgrades( //
5274
upgrade13To14);
5375
}
5476

77+
/**
78+
* Builds a registry that groups provided upgrades by their source version.
79+
*
80+
* @param upgrades varargs of available DatabaseUpgrade instances to register
81+
* @return a map from source version to the list of upgrades that start at that version; each list is sorted in descending (reverse natural) order
82+
*/
5583
private Map<Integer, List<DatabaseUpgrade>> defineUpgrades(DatabaseUpgrade... upgrades) {
5684
Map<Integer, List<DatabaseUpgrade>> result = new HashMap<>();
5785
for (DatabaseUpgrade upgrade : upgrades) {

data/src/main/java/org/cryptomator/data/db/Upgrade13To14.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ import timber.log.Timber
1010
@Singleton
1111
internal class Upgrade13To14 @Inject constructor(private val sharedPreferencesHandler: SharedPreferencesHandler) : DatabaseUpgrade(13, 14) {
1212

13+
/**
14+
* Applies the schema migration steps from version 13 to 14 on the provided database.
15+
*
16+
* If `origin > 0` (an existing installation), marks the welcome flow completed. For builds that
17+
* require migrating a license token (non-premium flavor), reads an existing `LICENSE_TOKEN` from
18+
* the database and saves it to shared preferences. In all cases, removes the `LICENSE_TOKEN`
19+
* column/data from the database.
20+
*
21+
* @param db The database to migrate.
22+
* @param origin The originating schema version; values greater than 0 indicate an existing install.
23+
*/
1324
override fun internalApplyTo(db: Database, origin: Int) {
1425
if (origin > 0) {
1526
// Any user going through a schema migration is an existing user — skip welcome
@@ -24,10 +35,23 @@ internal class Upgrade13To14 @Inject constructor(private val sharedPreferencesHa
2435
removeLicenseFromDb(db)
2536
}
2637

38+
/**
39+
* Indicates whether the current build uses the premium flavor (i.e., does not store a license key in the database).
40+
*
41+
* @return `true` if the current build is the premium flavor, `false` otherwise.
42+
*/
2743
private fun nonLicenseKeyVariant(): Boolean {
2844
return FlavorConfig.isPremiumFlavor
2945
}
3046

47+
/**
48+
* Removes the `LICENSE_TOKEN` column from the `UPDATE_CHECK_ENTITY` table by recreating the table without that column.
49+
*
50+
* The existing rows for `_id`, `RELEASE_NOTE`, `VERSION`, `URL_TO_APK`, `APK_SHA256`, and `URL_TO_RELEASE_NOTE` are preserved
51+
* by copying them into the new table. The operation is executed within a database transaction.
52+
*
53+
* @param db The database to modify.
54+
*/
3155
private fun removeLicenseFromDb(db: Database) {
3256
db.beginTransaction()
3357
try {
@@ -55,6 +79,12 @@ internal class Upgrade13To14 @Inject constructor(private val sharedPreferencesHa
5579
}
5680
}
5781

82+
/**
83+
* Retrieves the existing license token from the UPDATE_CHECK_ENTITY table.
84+
*
85+
* @param db The database to query.
86+
* @return The `LICENSE_TOKEN` value from the first row if present, `null` otherwise.
87+
*/
5888
private fun getExistingLicenseToken(db: Database): String? {
5989
Sql.query("UPDATE_CHECK_ENTITY")
6090
.columns(listOf("LICENSE_TOKEN"))
@@ -66,6 +96,11 @@ internal class Upgrade13To14 @Inject constructor(private val sharedPreferencesHa
6696
return null
6797
}
6898

99+
/**
100+
* Marks the onboarding welcome flow as completed in shared preferences.
101+
*
102+
* Sets the flag that causes the welcome screen to be skipped on subsequent launches.
103+
*/
69104
private fun setWelcomeFlowCompleted() {
70105
sharedPreferencesHandler.setWelcomeFlowCompleted()
71106
Timber.tag("Upgrade13To14").i("Skip welcome screen")

data/src/main/java/org/cryptomator/data/db/entities/UpdateCheckEntity.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,24 @@ public class UpdateCheckEntity extends DatabaseEntity {
2020

2121
private String urlToReleaseNote;
2222

23+
/**
24+
* Constructs a new UpdateCheckEntity with all fields unset (null).
25+
*
26+
* <p>Required by the persistence framework for entity instantiation.</p>
27+
*/
2328
public UpdateCheckEntity() {
2429
}
2530

31+
/**
32+
* Creates a new UpdateCheckEntity with the given metadata.
33+
*
34+
* @param id primary key (may be null before persistence)
35+
* @param releaseNote release note text or reference
36+
* @param version version string of the release
37+
* @param urlToApk download URL for the APK
38+
* @param apkSha256 SHA-256 checksum of the APK
39+
* @param urlToReleaseNote URL referencing the release notes
40+
*/
2641
@Generated(hash = 867488251)
2742
public UpdateCheckEntity(Long id, String releaseNote, String version, String urlToApk, String apkSha256, String urlToReleaseNote) {
2843
this.id = id;
@@ -38,10 +53,20 @@ public Long getId() {
3853
return id;
3954
}
4055

56+
/**
57+
* Sets the entity's primary key.
58+
*
59+
* @param id the primary key value, or null if not yet assigned
60+
*/
4161
public void setId(Long id) {
4262
this.id = id;
4363
}
4464

65+
/**
66+
* Gets the version string of the update.
67+
*
68+
* @return the version string, or {@code null} if not set
69+
*/
4570
public String getVersion() {
4671
return this.version;
4772
}

data/src/main/java/org/cryptomator/data/repository/HubRepositoryImpl.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,29 @@ public HubRepositoryImpl(Context context) {
4949
this.context = context;
5050
}
5151

52+
/**
53+
* Creates an OkHttp logging interceptor that logs HTTP messages to Timber using the "OkHttp" tag.
54+
*
55+
* @param context Android Context used to initialize the interceptor
56+
* @return an Interceptor that forwards OkHttp log messages to Timber with tag "OkHttp"
57+
*/
5258
private Interceptor httpLoggingInterceptor(Context context) {
5359
HttpLoggingInterceptor.Logger logger = message -> Timber.tag("OkHttp").d(message);
5460
return new HttpLoggingInterceptor(logger, context);
5561
}
5662

63+
/**
64+
* Retrieves the vault's JWE access token and subscription state from the Hub.
65+
*
66+
* @param unverifiedHubVaultConfig configuration that provides the Hub API base URL and vault identifier
67+
* @param accessToken Bearer access token for authorization
68+
* @return a {@link HubRepository.VaultAccess} containing the JWE payload and the vault subscription state
69+
* @throws HubLicenseUpgradeRequiredException if the Hub responds with HTTP 402 (payment required)
70+
* @throws HubVaultAccessForbiddenException if the Hub responds with HTTP 403 (forbidden)
71+
* @throws HubVaultIsArchivedException if the Hub responds with HTTP 410 (gone / archived)
72+
* @throws HubUserSetupRequiredException if the Hub responds with status 449 (user setup required)
73+
* @throws FatalBackendException for other HTTP failures, missing response body on HTTP 200, or I/O errors
74+
*/
5775
@Override
5876
public HubRepository.VaultAccess getVaultAccess(UnverifiedHubVaultConfig unverifiedHubVaultConfig, String accessToken) throws BackendException {
5977
var request = new Request.Builder().get() //

data/src/main/java/org/cryptomator/data/repository/UpdateCheckRepositoryImpl.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ private OkHttpClient httpClient() {
6464
.build();
6565
}
6666

67+
/**
68+
* Checks whether a newer application version is available for the provided current version.
69+
*
70+
* If a newer version is found, the method fetches update details, updates the cached
71+
* UpdateCheckEntity (id 1) with APK URL, version and SHA-256, persists the cache, and
72+
* returns an UpdateCheck describing the update. If the provided version already matches
73+
* the latest known version, no update is performed and the result is absent.
74+
*
75+
* @param appVersion the current application version to compare against the latest metadata
76+
* @return an Optional containing an UpdateCheck when an update is available; Optional.absent() when the appVersion matches the latest version
77+
* @throws BackendException if fetching, verifying, or processing remote update metadata fails
78+
*/
6779
@Override
6880
public Optional<UpdateCheck> getUpdateCheck(final String appVersion) throws BackendException {
6981
LatestVersion latestVersion = loadLatestVersion();
@@ -88,6 +100,13 @@ public Optional<UpdateCheck> getUpdateCheck(final String appVersion) throws Back
88100
return Optional.of(updateCheck);
89101
}
90102

103+
/**
104+
* Downloads the APK pointed to by the cached update entity into the provided file and verifies its SHA-256.
105+
*
106+
* @param file the destination file to write the downloaded APK to
107+
* @throws HashMismatchUpdateCheckException if the downloaded file's SHA-256 does not match the expected value
108+
* @throws GeneralUpdateErrorException for network, I/O, or non-success HTTP status code errors encountered while downloading
109+
*/
91110
@Override
92111
public void update(File file) throws GeneralUpdateErrorException {
93112
try {

domain/src/main/java/org/cryptomator/domain/Vault.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public class Vault implements Serializable {
2121
private final boolean hubVault;
2222
private final boolean hubPaidLicense;
2323

24+
/**
25+
* Creates a Vault instance from the given Builder's validated state.
26+
*
27+
* @param builder the Builder containing the validated properties to initialize this Vault
28+
*/
2429
private Vault(Builder builder) {
2530
this.id = builder.id;
2631
this.name = builder.name;
@@ -37,10 +42,25 @@ private Vault(Builder builder) {
3742
this.hubPaidLicense = builder.hubPaidLicense;
3843
}
3944

45+
/**
46+
* Create a new Builder for configuring and constructing a Vault.
47+
*
48+
* @return a Builder instance initialized with default values for building a Vault
49+
*/
4050
public static Builder aVault() {
4151
return new Builder();
4252
}
4353

54+
/**
55+
* Create a Builder pre-populated from an existing Vault.
56+
*
57+
* The returned Builder is initialized with the vault's id, cloud, cloudType, name, path,
58+
* unlocked state, saved password and its crypto mode, format, shortening threshold, position,
59+
* and hub-related flags.
60+
*
61+
* @param vault the source Vault to copy properties from
62+
* @return a Builder initialized with the source vault's properties
63+
*/
4464
public static Builder aCopyOf(Vault vault) {
4565
return new Builder() //
4666
.withId(vault.getId()) //
@@ -57,6 +77,11 @@ public static Builder aCopyOf(Vault vault) {
5777
.withHubPaidLicense(vault.hasHubPaidLicense());
5878
}
5979

80+
/**
81+
* Gets the vault's identifier.
82+
*
83+
* @return the vault id, or {@code null} if the vault has no assigned identifier
84+
*/
6085
public Long getId() {
6186
return id;
6287
}
@@ -101,18 +126,39 @@ public int getPosition() {
101126
return position;
102127
}
103128

129+
/**
130+
* Indicates whether this vault is read-only.
131+
*
132+
* @return `true` if the vault is read-only, `false` otherwise.
133+
*/
104134
public boolean isReadOnly() {
105135
return false; //TODO Implement read-only check
106136
}
107137

138+
/**
139+
* Indicates whether this vault is managed by Hub.
140+
*
141+
* @return true if the vault is a Hub vault, false otherwise.
142+
*/
108143
public boolean isHubVault() {
109144
return hubVault;
110145
}
111146

147+
/**
148+
* Indicates whether the vault has an associated Hub paid license.
149+
*
150+
* @return `true` if the vault has a Hub paid license, `false` otherwise.
151+
*/
112152
public boolean hasHubPaidLicense() {
113153
return hubPaidLicense;
114154
}
115155

156+
/**
157+
* Determines whether the given object represents the same Vault, using instance identity or matching non-null vault id.
158+
*
159+
* @param obj the object to compare with this Vault
160+
* @return `true` if {@code obj} is the same instance or a {@code Vault} whose non-null id equals this vault's id, `false` otherwise
161+
*/
116162
@Override
117163
public boolean equals(Object obj) {
118164
if (obj == null || getClass() != obj.getClass()) {
@@ -149,6 +195,9 @@ public static class Builder {
149195
private boolean hubVault;
150196
private boolean hubPaidLicense;
151197

198+
/**
199+
* Creates a new Builder initialized with default field values.
200+
*/
152201
private Builder() {
153202
}
154203

@@ -219,21 +268,45 @@ public Builder withFormat(int version) {
219268
return this;
220269
}
221270

271+
/**
272+
* Sets the filename shortening threshold for the vault being built.
273+
*
274+
* @param shorteningThreshold the threshold value at which shortening is applied (use -1 to leave unset)
275+
* @return this builder instance
276+
*/
222277
public Builder withShorteningThreshold(int shorteningThreshold) {
223278
this.shorteningThreshold = shorteningThreshold;
224279
return this;
225280
}
226281

282+
/**
283+
* Sets whether the vault has an associated Hub paid license.
284+
*
285+
* @param hubPaidLicense true if the vault has a Hub paid license, false otherwise
286+
* @return this Builder instance for chaining
287+
*/
227288
public Builder withHubPaidLicense(boolean hubPaidLicense) {
228289
this.hubPaidLicense = hubPaidLicense;
229290
return this;
230291
}
231292

293+
/**
294+
* Marks the vault under construction as a Hub vault.
295+
*
296+
* @param hubVault `true` to mark the vault as a Hub-managed vault, `false` otherwise
297+
* @return this builder
298+
*/
232299
public Builder withHubVault(boolean hubVault) {
233300
this.hubVault = hubVault;
234301
return this;
235302
}
236303

304+
/**
305+
* Sets the vault's position used for ordering.
306+
*
307+
* @param position numeric position used for ordering; must be set to a value other than -1 before calling {@code build()}
308+
* @return this Builder instance
309+
*/
237310
public Builder withPosition(int position) {
238311
this.position = position;
239312
return this;

domain/src/main/java/org/cryptomator/domain/repository/HubRepository.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,25 @@ import org.cryptomator.domain.exception.BackendException
55

66
interface HubRepository {
77

8+
/**
9+
* Retrieves vault access data for the specified unverified hub vault configuration using the provided access token.
10+
*
11+
* @param unverifiedHubVaultConfig The unverified hub vault configuration that identifies the vault.
12+
* @param accessToken The access token to authenticate the request against the hub.
13+
* @return A [VaultAccess] containing the vault key in JWE form and the vault's subscription state.
14+
* @throws BackendException If the backend request fails or access is denied.
15+
*/
816
@Throws(BackendException::class)
917
fun getVaultAccess(unverifiedHubVaultConfig: UnverifiedHubVaultConfig, accessToken: String): VaultAccess
1018

19+
/**
20+
* Fetches the hub user associated with the given unverified hub vault configuration and access token.
21+
*
22+
* @param unverifiedHubVaultConfig The unverified hub vault configuration identifying the vault context.
23+
* @param accessToken The access token used to authenticate the request against the hub.
24+
* @return A UserDto containing the user's id, name, public key, private key, and setup code.
25+
* @throws BackendException If the backend request fails or returns an error.
26+
*/
1127
@Throws(BackendException::class)
1228
fun getUser(unverifiedHubVaultConfig: UnverifiedHubVaultConfig, accessToken: String): UserDto
1329

0 commit comments

Comments
 (0)