Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Change ProfileId defaulting to be an invalid profile #5440

Open
BenHenning opened this issue Jun 22, 2024 · 2 comments
Open
Labels
enhancement End user-perceivable enhancements. Impact: Medium Moderate perceived user impact (non-blocking bugs and general improvements). Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet.

Comments

@BenHenning
Copy link
Member

BenHenning commented Jun 22, 2024

Is your feature request related to a problem? Please describe.

Currently, a default (unspecified) proto3 proto message will default its integers to 0. In the case of ProfileId, this means it defaults to an internal profile ID of 0.

An oversight when designing the profile management system is that the admin profile (first profile created on the device) is also initialized to 0, despite the default logged out ID being -1. This creates a potentially buggy inconsistency where code may assume a default, uninitialized ProfileId corresponds to an invalid profile when, in reality, it probably corresponds to the admin profile.

Describe the solution you'd like

ProfileId needs to be refactored to have a proper uninitialized state, which can probably be best done by introduce a logged out value:

message ProfileId {
  oneof type {
    int32 logged_in_internal_profile_id = 1;
    bool logged_out = 2; // Can be true or false; presence is sufficient.
  }
}

This should be binary compatible with the existing ProfileId, but it changes the semantics of default ProfileId to be an unspecified type, rather than a type that's logged in.

However, this requires substantial changes still throughout the codebase, namely:

  • All assumptions (including in ProfileManagementController) that '-1' means 'logged out' should be changed to use an actual logged-out state ProfileId.
  • All cases where internalProfileId is extracted from a ProfileId need to be checked to ensure that ProfileId's type is the correct logged-in case.

Describe alternatives you've considered

Haven't considered alternatives, but there are likely many approaches to this problem.

Additional context

Came up during review of #5248 but I was aware of it prior to that PR since it's existed as an issue since the introduction of profiles support.

@jainv4156
Copy link
Contributor

jainv4156 commented Feb 13, 2025

Hey, can I take this issue? I have a basic understanding of the profile management code and the solution proposed above. I just want to confirm if I’ve understood the situation correctly: When we first start the app, the default internal profile ID is 0, indicating the logged-out state. After manually logging out, the internal profile ID remains 0. Additionally, when the admin profile is created, its profile ID is also set to 0. What I’d like to confirm is the role of the default logged-out ID being -1. Are we referencing the logged-out state in the code with -1, while in the logged-out state, the internal ID is 0? If the above is correct, can I propose an alternate solution?

@jainv4156
Copy link
Contributor

@adhiamboperes Here is the draft PR: #5730. Can you take a look at it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement End user-perceivable enhancements. Impact: Medium Moderate perceived user impact (non-blocking bugs and general improvements). Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet.
Development

Successfully merging a pull request may close this issue.

4 participants