Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

[Full Changelog](In progress)

## ⚠️ Breaking Changes ⚠️

### Logins
- Kotlin: KeyRegenerationEventReason value names now use UPPER_SNAKE_CASE naming.
e.g. KeyRegenerationEventReason.Lost is now KeyRegenerationEventReason.LOST.

# v162.0 (_2026-11-19_)

[Full Changelog](https://github.com/mozilla/application-services/compare/v161.0...v162.0)
Expand Down
21 changes: 14 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ members = [
"components/support/guid",
"components/support/interrupt",
"components/support/jwcrypto",
"components/support/metrics",
"components/support/nimbus-cli",
"components/support/nimbus-fml",
"components/support/payload",
Expand Down
1 change: 1 addition & 0 deletions components/logins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jwcrypto = { path = "../support/jwcrypto" }
nss-as = { path = "../support/rc_crypto/nss", default-features = false }
interrupt-support = { path = "../support/interrupt" }
error-support = { path = "../support/error" }
metrics-support = { path = "../support/metrics" }
rusqlite = { version = "0.37.0", features = ["limits", "unlock_notify"] }
sync-guid = { path = "../support/guid", features = ["rusqlite_support", "random"] }
thiserror = "2"
Expand Down
20 changes: 1 addition & 19 deletions components/logins/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
// in mozilla-central there's no build.gradle suitable for the maven/glean config, so each component gets it.
// in mozilla-central there's no build.gradle suitable for the maven config, so each component gets it.
if (gradle.hasProperty("mozconfig")) {
repositories {
gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
Expand All @@ -11,27 +11,12 @@ buildscript {
}
}
}

dependencies {
classpath libs.mozilla.glean.gradle.plugin
}
}
}

apply from: "$appServicesRootDir/build-scripts/component-common.gradle"
apply from: "$publishDir/publish.gradle"

// Needs to happen before `dependencies` in order for the variables
// exposed by the plugin to be available for this project.
ext {
gleanNamespace = "mozilla.telemetry.glean"
gleanYamlFiles = ["${project.projectDir}/../metrics.yaml"]
if (gradle.hasProperty("mozconfig")) {
gleanPythonEnvDir = gradle.mozconfig.substs.GRADLE_GLEAN_PARSER_VENV
}
}
apply plugin: "org.mozilla.telemetry.glean-gradle-plugin"

android {
namespace = 'org.mozilla.appservices.logins'
}
Expand All @@ -44,13 +29,10 @@ dependencies {

implementation project(':init_rust_components')

implementation libs.mozilla.glean

testImplementation project(":syncmanager")

testImplementation libs.androidx.test.core
testImplementation libs.androidx.work.testing
testImplementation libs.mozilla.glean.forUnitTests
}

ext.configureUniFFIBindgen("logins")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@

package mozilla.appservices.logins

/*
* Import some private Glean types, so that we can use them in type declarations.
*
* I do not like importing these private classes, but I do like the nice generic
* code they allow me to write! By agreement with the Glean team, we must not
* instantiate anything from these classes, and it's on us to fix any bustage
* on version updates.
*/

import mozilla.appservices.db_crypto.KeyManager
import mozilla.appservices.db_crypto.createManagedEncdec
import mozilla.telemetry.glean.private.CounterMetricType
import mozilla.telemetry.glean.private.LabeledMetricType
import org.mozilla.appservices.logins.GleanMetrics.LoginsStore as LoginsStoreMetrics

/**
* An artifact of the uniffi conversion - a thin-ish wrapper around a
Expand Down Expand Up @@ -136,77 +124,6 @@ class DatabaseLoginsStorage(dbPath: String, keyManager: KeyManager) : AutoClosea

@Throws(LoginsApiException::class)
fun deleteUndecryptableLoginsAndRecordMetrics() {
val result = store.deleteUndecryptableRecordsForRemoteReplacement()
if (result.localDeleted > 0u) {
LoginsStoreMetrics.localUndecryptableDeleted.add(result.localDeleted.toInt())
}
if (result.mirrorDeleted > 0u) {
LoginsStoreMetrics.mirrorUndecryptableDeleted.add(result.mirrorDeleted.toInt())
}
}
}

enum class KeyRegenerationEventReason {
Lost, Corrupt, Other,
}

fun recordKeyRegenerationEvent(reason: KeyRegenerationEventReason) {
// Avoid the deprecation warning when calling `record()` without the optional EventExtras param
@Suppress("DEPRECATION")
when (reason) {
KeyRegenerationEventReason.Lost -> LoginsStoreMetrics.keyRegeneratedLost.record()
KeyRegenerationEventReason.Corrupt -> LoginsStoreMetrics.keyRegeneratedCorrupt.record()
KeyRegenerationEventReason.Other -> LoginsStoreMetrics.keyRegeneratedOther.record()
}
}

/**
* A helper class for gathering basic count metrics on different kinds of LoginsStore operation.
*
* For each type of operation, we want to measure:
* - total count of operations performed
* - count of operations that produced an error, labeled by type
*
* This is a convenience wrapper to measure the two in one shot.
*/
class LoginsStoreCounterMetrics(
val count: CounterMetricType,
val errCount: LabeledMetricType<CounterMetricType>,
) {
inline fun <U> measure(callback: () -> U): U {
return measureIgnoring({ false }, callback)
}

@Suppress("ComplexMethod", "TooGenericExceptionCaught")
inline fun <U> measureIgnoring(
shouldIgnore: (Exception) -> Boolean,
callback: () -> U,
): U {
count.add()
try {
return callback()
} catch (e: Exception) {
if (shouldIgnore(e)) {
throw e
}
when (e) {
is LoginsApiException.NoSuchRecord -> {
errCount["no_such_record"].add()
}
is LoginsApiException.Interrupted -> {
errCount["interrupted"].add()
}
is LoginsApiException.InvalidRecord -> {
errCount["invalid_record"].add()
}
is LoginsApiException -> {
errCount["storage_error"].add()
}
else -> {
errCount["__other__"].add()
}
}
throw e
}
store.deleteUndecryptableRecordsForRemoteReplacement()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

package mozilla.appservices.logins

import androidx.test.core.app.ApplicationProvider
import mozilla.appservices.RustComponentsInitializer
import mozilla.appservices.db_crypto.KeyManager
import mozilla.appservices.db_crypto.createKey
import mozilla.appservices.db_crypto.createStaticKeyManager
import mozilla.appservices.syncmanager.SyncManager
import mozilla.telemetry.glean.testing.GleanTestRule
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
Expand All @@ -32,9 +30,6 @@ class DatabaseLoginsStorageTest {
@JvmField
val dbFolder = TemporaryFolder()

@get:Rule
val gleanRule = GleanTestRule(ApplicationProvider.getApplicationContext())

fun createTestStore(): DatabaseLoginsStorage {
RustComponentsInitializer.init()

Expand Down
6 changes: 1 addition & 5 deletions components/logins/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
# specific to the *syncing* of logins are defined in a separate "sync_ping"
# package.
#
# Changes to these metrics require data review, which should take into
# consideration the following known consumers of the logins component
# Android bindings:
#
# * Fenix for Android
# Changes to these metrics require data review.

---
$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0
Expand Down
27 changes: 7 additions & 20 deletions components/logins/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/// - After we sync, we move all records from loginsL to loginsM, overwriting any previous data.
/// loginsL will be an empty table after this. See mark_as_synchronized() for the details.
use crate::error::*;
use crate::glean_metrics;
use crate::login::*;
use crate::schema;
use crate::sync::SyncStatus;
Expand All @@ -49,11 +50,6 @@ pub struct LoginDb {
interrupt_handle: Arc<SqlInterruptHandle>,
}

pub struct LoginsDeletionMetrics {
pub local_deleted: u64,
pub mirror_deleted: u64,
}

impl LoginDb {
pub fn with_connection(db: Connection, encdec: Arc<dyn EncryptorDecryptor>) -> Result<Self> {
#[cfg(test)]
Expand Down Expand Up @@ -1088,9 +1084,7 @@ impl LoginDb {
Ok(result)
}

pub fn delete_undecryptable_records_for_remote_replacement(
&self,
) -> Result<LoginsDeletionMetrics> {
pub fn delete_undecryptable_records_for_remote_replacement(&self) -> Result<()> {
// Retrieve a list of guids for logins that cannot be decrypted
let corrupted_logins = self
.get_all()?
Expand All @@ -1105,10 +1099,7 @@ impl LoginDb {
self.delete_local_records_for_remote_replacement(ids)
}

pub fn delete_local_records_for_remote_replacement(
&self,
ids: Vec<&str>,
) -> Result<LoginsDeletionMetrics> {
pub fn delete_local_records_for_remote_replacement(&self, ids: Vec<&str>) -> Result<()> {
let tx = self.unchecked_transaction_imm()?;
let mut local_deleted = 0;
let mut mirror_deleted = 0;
Expand Down Expand Up @@ -1138,10 +1129,9 @@ impl LoginDb {
})?;

tx.commit()?;
Ok(LoginsDeletionMetrics {
local_deleted: local_deleted as u64,
mirror_deleted: mirror_deleted as u64,
})
glean_metrics::logins_store::local_undecryptable_deleted.add(local_deleted as i32);
glean_metrics::logins_store::mirror_undecryptable_deleted.add(mirror_deleted as i32);
Ok(())
}

fn mark_mirror_overridden(&self, guid: &str) -> Result<()> {
Expand Down Expand Up @@ -2736,17 +2726,14 @@ mod tests {
})
.unwrap();

let result = db
.delete_local_records_for_remote_replacement(vec![login.guid_str()])
db.delete_local_records_for_remote_replacement(vec![login.guid_str()])
.unwrap();

let local_guids = get_local_guids(&db);
assert_eq!(local_guids.len(), 0);

let mirror_guids = get_mirror_guids(&db);
assert_eq!(mirror_guids.len(), 0);

assert_eq!(result.local_deleted, 1);
}

mod test_find_login_to_update {
Expand Down
25 changes: 25 additions & 0 deletions components/logins/src/key_regeneration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::glean_metrics;

pub enum KeyRegenerationEventReason {
Lost,
Corrupt,
Other,
}

pub fn record_key_regeneration_event(reason: KeyRegenerationEventReason) {
match reason {
KeyRegenerationEventReason::Lost => {
glean_metrics::logins_store::key_regenerated_lost.record(None);
}
KeyRegenerationEventReason::Corrupt => {
glean_metrics::logins_store::key_regenerated_corrupt.record(None);
}
KeyRegenerationEventReason::Other => {
glean_metrics::logins_store::key_regenerated_other.record(None);
}
}
}
Loading
Loading