mirror of
https://github.com/bitwarden/android.git
synced 2026-05-10 16:45:43 -05:00
Compare commits
126 Commits
release/20
...
BRE-1305/p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4607dad9c5 | ||
|
|
759e459165 | ||
|
|
3952bff558 | ||
|
|
132263a093 | ||
|
|
6ce65db380 | ||
|
|
d14f0c4b34 | ||
|
|
8542cb81c7 | ||
|
|
46b7e07b6c | ||
|
|
655a33f5b7 | ||
|
|
66c355db35 | ||
|
|
6bb68d7f3e | ||
|
|
2a014d76f3 | ||
|
|
05a026cd23 | ||
|
|
858bdebb6c | ||
|
|
f0d3389688 | ||
|
|
9736d8532e | ||
|
|
8bdbccd8de | ||
|
|
a75d904317 | ||
|
|
a395f28eba | ||
|
|
53e358d7b3 | ||
|
|
663eb3641f | ||
|
|
ab305b2631 | ||
|
|
946b0784e0 | ||
|
|
167a46a073 | ||
|
|
7b491d3c3c | ||
|
|
7918abdccf | ||
|
|
5ec0a1986d | ||
|
|
839e9e8a1a | ||
|
|
979237b751 | ||
|
|
621f97d161 | ||
|
|
d81b0005ee | ||
|
|
794b27a750 | ||
|
|
169b21cfdb | ||
|
|
4623a4f079 | ||
|
|
21afa81322 | ||
|
|
55c7ab4cee | ||
|
|
7a40bfe522 | ||
|
|
0c234ee0aa | ||
|
|
7b0b93a204 | ||
|
|
473416c1b4 | ||
|
|
f3646790e3 | ||
|
|
35b87f4390 | ||
|
|
7120eefc94 | ||
|
|
5eb56cafaa | ||
|
|
b2d94fae40 | ||
|
|
ad748eef7f | ||
|
|
8010e8d6c3 | ||
|
|
7a6a493f24 | ||
|
|
4032d2bb5c | ||
|
|
e2c9aae9c1 | ||
|
|
56566b958c | ||
|
|
06bf603ec8 | ||
|
|
79d6da0a61 | ||
|
|
2d2ea9acee | ||
|
|
05d6fe1ba1 | ||
|
|
1024f77ddf | ||
|
|
50e50eb08c | ||
|
|
bd98df6eb9 | ||
|
|
9baec6e6a5 | ||
|
|
efd15b027c | ||
|
|
b715a51188 | ||
|
|
94ed32790f | ||
|
|
dca97e0c8e | ||
|
|
aceb96d18f | ||
|
|
510072b34f | ||
|
|
7324be04f4 | ||
|
|
bfbe47f48f | ||
|
|
2bb06063c7 | ||
|
|
ed47ff4d18 | ||
|
|
448ba97ae2 | ||
|
|
14e833247d | ||
|
|
4b7fcdb6ea | ||
|
|
0959284e6f | ||
|
|
1f24ca7de1 | ||
|
|
dc79176274 | ||
|
|
a631d6822a | ||
|
|
845a5dec22 | ||
|
|
b1195b5f46 | ||
|
|
8de3a07715 | ||
|
|
9c4bd2ee14 | ||
|
|
6dad8c4def | ||
|
|
bc74337eae | ||
|
|
d86443c6dd | ||
|
|
d07b119802 | ||
|
|
dbf2e9f68a | ||
|
|
9ddfd376a9 | ||
|
|
dd1dbd0b97 | ||
|
|
f6be363e98 | ||
|
|
600744538d | ||
|
|
de33ba021b | ||
|
|
290f59441f | ||
|
|
94c51cacf9 | ||
|
|
6f27642a30 | ||
|
|
2ad3014da2 | ||
|
|
e6dc8e02f8 | ||
|
|
c16d31fb33 | ||
|
|
43d7b84d0a | ||
|
|
c0f8307361 | ||
|
|
064a98f86b | ||
|
|
e3b111c383 | ||
|
|
52304a266e | ||
|
|
51c23ec464 | ||
|
|
7d7951d4ca | ||
|
|
78b1676745 | ||
|
|
be27c76bd3 | ||
|
|
38bdda0a41 | ||
|
|
c61fec176a | ||
|
|
bb11b17823 | ||
|
|
562b48d689 | ||
|
|
c3496ca60f | ||
|
|
a8f8450ec9 | ||
|
|
47628a6da2 | ||
|
|
5a540a3460 | ||
|
|
92cfce1224 | ||
|
|
4597337500 | ||
|
|
e610a7541d | ||
|
|
ae4b398258 | ||
|
|
0482f9eb4d | ||
|
|
9f4bd70c8d | ||
|
|
9874aad65a | ||
|
|
97bb93c18e | ||
|
|
31e7e05eda | ||
|
|
afeeb494da | ||
|
|
d5912a5dc3 | ||
|
|
13fa8a1ed0 | ||
|
|
5a145ee163 |
105
.claude/CLAUDE.md
Normal file
105
.claude/CLAUDE.md
Normal file
@@ -0,0 +1,105 @@
|
||||
# Claude Guidelines
|
||||
|
||||
Core directives for maintaining code quality and consistency in the Bitwarden Android project.
|
||||
|
||||
## Core Directives
|
||||
|
||||
**You MUST follow these directives at all times.**
|
||||
|
||||
1. **Adhere to Architecture**: All code modifications MUST follow patterns in `docs/ARCHITECTURE.md`
|
||||
2. **Follow Code Style**: ALWAYS follow `docs/STYLE_AND_BEST_PRACTICES.md`
|
||||
3. **Error Handling**: Use Result types and sealed classes per architecture guidelines
|
||||
4. **Best Practices**: Follow Kotlin idioms (immutability, appropriate data structures, coroutines)
|
||||
5. **Document Everything**: All public APIs require KDoc documentation
|
||||
6. **Dependency Management**: Use Hilt DI patterns as established in the project
|
||||
7. **Use Established Patterns**: Leverage existing components before creating new ones
|
||||
8. **File References**: Use file:line_number format when referencing code
|
||||
|
||||
## Code Quality Standards
|
||||
|
||||
### Module Organization
|
||||
|
||||
**Core Library Modules:**
|
||||
- **`:core`** - Common utilities and managers shared across multiple modules
|
||||
- **`:data`** - Data sources, database, data repositories
|
||||
- **`:network`** - Networking interfaces, API clients, network utilities
|
||||
- **`:ui`** - Reusable Bitwarden Composables, theming, UI utilities
|
||||
|
||||
**Application Modules:**
|
||||
- **`:app`** - Password Manager application, feature screens, ViewModels, DI setup
|
||||
- **`:authenticator`** - Authenticator application for 2FA/TOTP code generation
|
||||
|
||||
**Specialized Library Modules:**
|
||||
- **`:authenticatorbridge`** - Communication bridge between :authenticator and :app
|
||||
- **`:annotation`** - Custom annotations for code generation (Hilt, Room, etc.)
|
||||
- **`:cxf`** - Android Credential Exchange (CXF/CXP) integration layer
|
||||
|
||||
### Patterns Enforcement
|
||||
|
||||
- **MVVM + UDF**: ViewModels with StateFlow, Compose UI
|
||||
- **Hilt DI**: Interface injection, @HiltViewModel, @Inject constructor
|
||||
- **Testing**: JUnit 5, MockK, Turbine for Flow testing
|
||||
- **Error Handling**: Sealed Result types, no throws in business logic
|
||||
|
||||
## Security Requirements
|
||||
|
||||
**Every change must consider:**
|
||||
- Zero-knowledge architecture preservation
|
||||
- Proper encryption key handling (Android Keystore)
|
||||
- Input validation and sanitization
|
||||
- Secure data storage patterns
|
||||
- Threat model implications
|
||||
|
||||
## Workflow Practices
|
||||
|
||||
### Before Implementation
|
||||
|
||||
1. Read relevant architecture documentation
|
||||
2. Search for existing patterns to follow
|
||||
3. Identify affected modules and dependencies
|
||||
4. Consider security implications
|
||||
|
||||
### During Implementation
|
||||
|
||||
1. Follow existing code style in surrounding files
|
||||
2. Write tests alongside implementation
|
||||
3. Add KDoc to all public APIs
|
||||
4. Validate against architecture guidelines
|
||||
|
||||
### After Implementation
|
||||
|
||||
1. Ensure all tests pass
|
||||
2. Verify compilation succeeds
|
||||
3. Review security considerations
|
||||
4. Update relevant documentation
|
||||
|
||||
## Anti-Patterns
|
||||
|
||||
**Avoid these:**
|
||||
- Creating new patterns when established ones exist
|
||||
- Exception-based error handling in business logic
|
||||
- Direct dependency access (use DI)
|
||||
- Mutable state in ViewModels (use StateFlow)
|
||||
- Missing null safety handling
|
||||
- Undocumented public APIs
|
||||
- Tight coupling between modules
|
||||
|
||||
## Communication & Decision-Making
|
||||
|
||||
Always clarify ambiguous requirements before implementing. Use specific questions:
|
||||
- "Should this use [Approach A] or [Approach B]?"
|
||||
- "This affects [X]. Proceed or review first?"
|
||||
- "Expected behavior for [specific requirement]?"
|
||||
|
||||
Defer high-impact decisions to the user:
|
||||
- Architecture/module changes, public API modifications
|
||||
- Security mechanisms, database migrations
|
||||
- Third-party library additions
|
||||
|
||||
## Reference Documentation
|
||||
|
||||
Critical resources:
|
||||
- `docs/ARCHITECTURE.md` - Architecture patterns and principles
|
||||
- `docs/STYLE_AND_BEST_PRACTICES.md` - Code style guidelines
|
||||
|
||||
**Do not duplicate information from these files - reference them instead.**
|
||||
27
.claude/prompts/review-code.md
Normal file
27
.claude/prompts/review-code.md
Normal file
@@ -0,0 +1,27 @@
|
||||
Use the `reviewing-changes` skill to review this pull request.
|
||||
|
||||
The PR branch is already checked out in the current working directory.
|
||||
|
||||
## CRITICAL OUTPUT REQUIREMENTS
|
||||
|
||||
**Summary Format (REQUIRED):**
|
||||
- **Clean PRs (no issues)**: 2-3 lines MAXIMUM
|
||||
- Format: `**Overall Assessment:** APPROVE\n[One sentence]`
|
||||
- Example: "Clean refactoring following established patterns"
|
||||
|
||||
- **PRs with issues**: Verdict + critical issues list (5-10 lines MAX)
|
||||
- Format: `**Overall Assessment:** APPROVE/REQUEST CHANGES\n**Critical Issues:**\n- issue 1\nSee inline comments`
|
||||
- All details go in inline comments with `<details>` tags, NOT in summary
|
||||
|
||||
**NEVER create:**
|
||||
- ❌ Praise sections ("Strengths", "Good Practices", "Excellent X")
|
||||
- ❌ Verbose analysis sections (Architecture Assessment, Technical Review, Code Quality, etc.)
|
||||
- ❌ Tables, statistics, or detailed breakdowns in summary
|
||||
- ❌ Multiple summary sections
|
||||
- ❌ Checkmarks listing everything done correctly
|
||||
|
||||
**Inline Comments:**
|
||||
- Create separate inline comment for each specific issue/recommendation
|
||||
- Use collapsible `<details>` sections for code examples and explanations
|
||||
- Only severity + one-line description visible; all other content collapsed
|
||||
- Track status of previously identified issues if this is a subsequent review
|
||||
320
.claude/skills/reviewing-changes/SKILL.md
Normal file
320
.claude/skills/reviewing-changes/SKILL.md
Normal file
@@ -0,0 +1,320 @@
|
||||
---
|
||||
name: reviewing-changes
|
||||
version: 2.0.0
|
||||
description: Comprehensive code reviews for Bitwarden Android. Detects change type (dependency update, bug fix, feature, UI, refactoring, infrastructure) and applies appropriate review depth. Validates MVVM patterns, Hilt DI, security requirements, and test coverage per project standards. Use when reviewing pull requests, checking commits, analyzing code changes, or evaluating architectural compliance.
|
||||
---
|
||||
|
||||
# Reviewing Changes
|
||||
|
||||
## Instructions
|
||||
|
||||
**IMPORTANT**: Use structured thinking throughout your review process. Plan your analysis in `<thinking>` tags before providing final feedback. This improves accuracy by 40% according to research.
|
||||
|
||||
### Step 1: Check for Existing Review Threads
|
||||
|
||||
Always check for existing comment threads to avoid duplicate comments:
|
||||
|
||||
<thinking>
|
||||
Before creating any comments:
|
||||
1. Is this a fresh review or re-review of the same PR?
|
||||
2. What existing discussion might already exist?
|
||||
3. Which findings should update existing threads vs create new?
|
||||
</thinking>
|
||||
|
||||
**Thread Detection Procedure:**
|
||||
|
||||
1. **Fetch existing comment count:**
|
||||
```bash
|
||||
gh pr view <pr-number> --json comments --jq '.comments | length'
|
||||
```
|
||||
|
||||
2. **If count = 0:** No existing threads. Skip to Step 2 (all comments will be new).
|
||||
|
||||
3. **If count > 0:** Fetch full comment data to check for existing threads.
|
||||
```bash
|
||||
gh pr view <pr-number> --json comments --jq '.comments[] | {id, path, line, body}' > pr_comments.json
|
||||
```
|
||||
|
||||
4. **Parse existing threads:** Extract file paths, line numbers, and issue summaries from previous review comments.
|
||||
- Build map: `{file:line → {comment_id, issue_summary, resolved}}`
|
||||
- Note which issues already have active discussions
|
||||
|
||||
5. **Matching Strategy (Hybrid Approach):**
|
||||
When you identify an issue to comment on:
|
||||
- **Exact match:** Same file + same line number → existing thread found
|
||||
- **Nearby match:** Same file + line within ±5 → existing thread found
|
||||
- **No match:** Create new inline comment
|
||||
|
||||
6. **Handling Evolved Issues:**
|
||||
- **Issue persists unchanged:** Respond in existing thread with update
|
||||
- **Issue resolved:** Note resolution in thread response (can mark as resolved if supported)
|
||||
- **Issue changed significantly:** Resolve/close old thread, create new comment explaining evolution
|
||||
|
||||
### Step 2: Detect Change Type
|
||||
|
||||
<thinking>
|
||||
Analyze the changeset systematically:
|
||||
1. What files were modified? (code vs config vs docs)
|
||||
2. What is the PR/commit title indicating?
|
||||
3. Is there new functionality or just modifications?
|
||||
4. What's the risk level of these changes?
|
||||
</thinking>
|
||||
|
||||
Analyze the changeset to determine the primary change type:
|
||||
|
||||
**Detection Rules:**
|
||||
- **Dependency Update**: Only gradle files changed (`libs.versions.toml`, `build.gradle.kts`) with version number modifications
|
||||
- **Bug Fix**: PR/commit title contains "fix", "bug", or issue ID; addresses existing broken behavior
|
||||
- **Feature Addition**: New files, new ViewModels, significant new functionality
|
||||
- **UI Refinement**: Only UI/Compose files changed, layout/styling focus
|
||||
- **Refactoring**: Code restructuring without behavior change, pattern improvements
|
||||
- **Infrastructure**: CI/CD files, Gradle config, build scripts, tooling changes
|
||||
|
||||
If changeset spans multiple types, use the most complex type's checklist.
|
||||
|
||||
### Step 3: Load Appropriate Checklist
|
||||
|
||||
Based on detected type, read the relevant checklist file:
|
||||
|
||||
- **Dependency Update** → `checklists/dependency-update.md` (expedited review)
|
||||
- **Bug Fix** → `checklists/bug-fix.md` (focused review)
|
||||
- **Feature Addition** → `checklists/feature-addition.md` (comprehensive review)
|
||||
- **UI Refinement** → `checklists/ui-refinement.md` (design-focused review)
|
||||
- **Refactoring** → `checklists/refactoring.md` (pattern-focused review)
|
||||
- **Infrastructure** → `checklists/infrastructure.md` (tooling-focused review)
|
||||
|
||||
The checklist provides:
|
||||
- Multi-pass review strategy
|
||||
- Type-specific focus areas
|
||||
- What to check and what to skip
|
||||
- Structured thinking guidance
|
||||
|
||||
### Step 4: Execute Review with Structured Thinking
|
||||
|
||||
<thinking>
|
||||
Before diving into details:
|
||||
1. What are the highest-risk areas of this change?
|
||||
2. Which architectural patterns need verification?
|
||||
3. What security implications exist?
|
||||
4. How should I prioritize my findings?
|
||||
5. What tone is appropriate for this feedback?
|
||||
</thinking>
|
||||
|
||||
Follow the checklist's multi-pass strategy, thinking through each pass systematically.
|
||||
|
||||
### Step 5: Consult Reference Materials As Needed
|
||||
|
||||
Load reference files only when needed for specific questions:
|
||||
|
||||
- **Issue prioritization** → `reference/priority-framework.md` (Critical vs Suggested vs Optional)
|
||||
- **Phrasing feedback** → `reference/review-psychology.md` (questions vs commands, I-statements)
|
||||
- **Architecture questions** → `reference/architectural-patterns.md` (MVVM, Hilt DI, module org, error handling)
|
||||
- **Security questions (quick reference)** → `reference/security-patterns.md` (common patterns and anti-patterns)
|
||||
- **Security questions (comprehensive)** → `docs/ARCHITECTURE.md#security` (full zero-knowledge architecture)
|
||||
- **Testing questions** → `reference/testing-patterns.md` (unit tests, mocking, null safety)
|
||||
- **UI questions** → `reference/ui-patterns.md` (Compose patterns, theming)
|
||||
- **Style questions** → `docs/STYLE_AND_BEST_PRACTICES.md`
|
||||
|
||||
### Step 6: Document Findings
|
||||
|
||||
## 🛑 STOP: Determine Output Format FIRST
|
||||
|
||||
<thinking>
|
||||
Before writing ANY output, answer this critical question:
|
||||
1. Did I find ANY issues (Critical, Important, Suggested, or Questions)?
|
||||
2. If NO issues found → This is a CLEAN PR → Use 2-3 line minimal format and STOP
|
||||
3. If issues found → Use verdict + critical issues list + inline comments format
|
||||
4. NEVER create praise sections or elaborate on correct implementations
|
||||
</thinking>
|
||||
|
||||
**Decision Tree:**
|
||||
|
||||
```
|
||||
Do you have ANY issues to report (Critical/Important/Suggested/Questions)?
|
||||
│
|
||||
├─ NO → CLEAN PR
|
||||
│ └─ Use 2-3 line format:
|
||||
│ "**Overall Assessment:** APPROVE
|
||||
│ [One sentence describing what PR does well]"
|
||||
│ └─ STOP. Do not proceed to detailed format guidance.
|
||||
│
|
||||
└─ YES → PR WITH ISSUES
|
||||
└─ Use minimal summary + inline comments:
|
||||
"**Overall Assessment:** APPROVE / REQUEST CHANGES
|
||||
**Critical Issues:**
|
||||
- [issue with file:line]
|
||||
See inline comments for details."
|
||||
```
|
||||
|
||||
## Special Case: Clean PRs with No Issues
|
||||
|
||||
When you find NO critical, important, or suggested issues:
|
||||
|
||||
**Minimal Approval Format (REQUIRED):**
|
||||
```
|
||||
**Overall Assessment:** APPROVE
|
||||
|
||||
[One sentence describing what the PR does well]
|
||||
```
|
||||
|
||||
**Examples:**
|
||||
- "Clean refactoring following established patterns"
|
||||
- "Solid bug fix with comprehensive test coverage"
|
||||
- "Well-structured feature implementation meeting all standards"
|
||||
|
||||
**NEVER do this for clean PRs:**
|
||||
- ❌ Multiple sections (Key Strengths, Changes, Code Quality, etc.)
|
||||
- ❌ Listing everything that was done correctly
|
||||
- ❌ Checkmarks for each file or pattern followed
|
||||
- ❌ Elaborate praise or detailed positive analysis
|
||||
- ❌ Tables, statistics, or detailed breakdowns
|
||||
|
||||
**Why brevity matters:**
|
||||
- Respects developer time (quick approval = move forward faster)
|
||||
- Reduces noise in PR conversations
|
||||
- Saves tokens and processing time
|
||||
- Focuses attention on PRs that actually need discussion
|
||||
|
||||
**If you're tempted to write more than 3 lines for a clean PR, STOP. You're doing it wrong.**
|
||||
|
||||
---
|
||||
|
||||
<thinking>
|
||||
Before writing each comment:
|
||||
1. Is this issue Critical, Important, Suggested, or just Acknowledgment?
|
||||
2. Should I ask a question or provide direction?
|
||||
3. What's the rationale I need to explain?
|
||||
4. What code example would make this actionable?
|
||||
5. Is there a documentation reference to include?
|
||||
</thinking>
|
||||
|
||||
**CRITICAL**: Use summary comment + inline comments approach.
|
||||
|
||||
**Review Comment Structure**:
|
||||
- Create ONE summary comment with overall verdict + critical issues list
|
||||
- Create separate inline comment for EACH specific issue on the exact line with full details
|
||||
- Summary directs readers to inline comments ("See inline comments for details")
|
||||
- Do NOT duplicate issue details between summary and inline comments
|
||||
|
||||
### CRITICAL: No Praise-Only Comments
|
||||
|
||||
❌ **NEVER** create inline comments solely for positive feedback
|
||||
❌ **NEVER** create summary sections like "Strengths", "Good Practices", "What Went Well"
|
||||
❌ **NEVER** use inline comments to elaborate on correct implementations
|
||||
|
||||
Focus exclusively on actionable feedback. Reserve comments for issues requiring attention.
|
||||
|
||||
**Inline Comment Format** (REQUIRED: Use `<details>` Tags):
|
||||
|
||||
**MUST use `<details>` tags for ALL inline comments.** Only severity + one-line description should be visible; all other content must be collapsed.
|
||||
|
||||
```
|
||||
[emoji] **[SEVERITY]**: [One-line issue description]
|
||||
|
||||
<details>
|
||||
<summary>Details and fix</summary>
|
||||
|
||||
[Code example or specific fix]
|
||||
|
||||
[Rationale explaining why]
|
||||
|
||||
Reference: [docs link if applicable]
|
||||
</details>
|
||||
```
|
||||
|
||||
**Visibility Rule:**
|
||||
- **Visible:** Severity prefix (emoji + text) + one-line description
|
||||
- **Collapsed in `<details>`:** Code examples, rationale, explanations, references
|
||||
|
||||
**Example inline comment**:
|
||||
```
|
||||
⚠️ **CRITICAL**: Exposes mutable state
|
||||
|
||||
<details>
|
||||
<summary>Details and fix</summary>
|
||||
|
||||
Change `MutableStateFlow<State>` to `StateFlow<State>`:
|
||||
|
||||
\```kotlin
|
||||
private val _state = MutableStateFlow<State>()
|
||||
val state: StateFlow<State> = _state.asStateFlow()
|
||||
\```
|
||||
|
||||
Exposing MutableStateFlow allows external mutation, violating MVVM unidirectional data flow.
|
||||
|
||||
Reference: docs/ARCHITECTURE.md#mvvm-pattern
|
||||
</details>
|
||||
```
|
||||
|
||||
**Summary Comment Format (REQUIRED - No Exceptions):**
|
||||
|
||||
When you have issues to report, use this format ONLY:
|
||||
|
||||
```
|
||||
**Overall Assessment:** APPROVE / REQUEST CHANGES
|
||||
|
||||
**Critical Issues** (if any):
|
||||
- [One-line summary with file:line reference]
|
||||
|
||||
See inline comments for all details.
|
||||
```
|
||||
|
||||
**Maximum Length**: 5-10 lines total, regardless of PR size or complexity.
|
||||
|
||||
**No exceptions for**:
|
||||
- ❌ Large PRs (10+ files)
|
||||
- ❌ Multiple issue domains
|
||||
- ❌ High-severity issues
|
||||
- ❌ Complex changes
|
||||
|
||||
All details belong in inline comments with `<details>` tags, NOT in the summary.
|
||||
|
||||
**Output Format Rules**:
|
||||
|
||||
**What to Include:**
|
||||
- **Inline comments**: Create separate comment for EACH specific issue with full details in `<details>` tag
|
||||
- **Summary comment**: Overall assessment (APPROVE/REQUEST CHANGES) + list of CRITICAL issues only
|
||||
- **Severity levels** (hybrid emoji + text format):
|
||||
- ⚠️ **CRITICAL** (blocking)
|
||||
- 📋 **IMPORTANT** (should fix)
|
||||
- 💡 **SUGGESTED** (nice to have)
|
||||
- ❓ **QUESTION** (seeking clarification)
|
||||
|
||||
**What to Exclude:**
|
||||
- **No duplication**: Never repeat inline comment details in the summary
|
||||
- **No Important/Suggested in summary**: Only CRITICAL blocking issues belong in summary
|
||||
- **No "Good Practices"/"Strengths" sections**: Never include positive commentary sections
|
||||
- **No "Action Items" section**: This duplicates inline comments - avoid entirely
|
||||
- **No verbose analysis**: Keep detailed analysis (compilation status, security review, rollback plans) in inline comments only
|
||||
|
||||
### ❌ Common Anti-Patterns to Avoid
|
||||
|
||||
**DO NOT:**
|
||||
- Create multiple summary sections (Strengths, Recommendations, Test Coverage Status, Architecture Compliance)
|
||||
- Duplicate critical issues in both summary and inline comments
|
||||
- Write elaborate descriptions in summary (details belong in inline comments)
|
||||
- Exceed 5-10 lines for simple PRs
|
||||
- Create inline comments that only provide praise
|
||||
|
||||
**DO:**
|
||||
- Put verdict + critical issue list ONLY in summary
|
||||
- Put ALL details (explanations, code, rationale) in inline comments with `<details>` collapse
|
||||
- Keep summary to 5-10 lines maximum, regardless of PR size or your analysis depth
|
||||
- Focus comments exclusively on actionable issues
|
||||
|
||||
**Visibility Guidelines:**
|
||||
- **Inline comments visible**: Severity + one-line description only
|
||||
- **Inline comments collapsed**: Code examples, rationale, references in `<details>` tag
|
||||
- **Summary visible**: Verdict + critical issues list only
|
||||
|
||||
See `examples/review-outputs.md` for complete examples.
|
||||
|
||||
## Core Principles
|
||||
|
||||
- **Minimal reviews for clean PRs**: 2-3 lines when no issues found (see Step 6 format guidance)
|
||||
- **Issues-focused feedback**: Only comment when there's something actionable; acknowledge good work briefly without elaboration (see priority-framework.md:145-166)
|
||||
- **Appropriate depth**: Match review rigor to change complexity and risk
|
||||
- **Specific references**: Always use `file:line_number` format for precise location
|
||||
- **Actionable feedback**: Say what to do and why, not just what's wrong
|
||||
- **Constructive tone**: Ask questions for design decisions, explain rationale, focus on code not people
|
||||
- **Efficient reviews**: Use multi-pass strategy, time-box reviews, skip what's not relevant
|
||||
164
.claude/skills/reviewing-changes/checklists/bug-fix.md
Normal file
164
.claude/skills/reviewing-changes/checklists/bug-fix.md
Normal file
@@ -0,0 +1,164 @@
|
||||
# Bug Fix Review Checklist
|
||||
|
||||
## Multi-Pass Strategy
|
||||
|
||||
### First Pass: Understand the Bug
|
||||
|
||||
<thinking>
|
||||
Before evaluating the fix:
|
||||
1. What was the original bug/broken behavior?
|
||||
2. What is the expected correct behavior?
|
||||
3. What was the root cause?
|
||||
4. How was the bug discovered? (user report, test, production)
|
||||
5. What's the severity? (crash, data loss, UI glitch, minor annoyance)
|
||||
</thinking>
|
||||
|
||||
**1. Understand root cause:**
|
||||
- What was the broken behavior?
|
||||
- What caused it?
|
||||
- How does this fix address the root cause?
|
||||
|
||||
**2. Assess scope:**
|
||||
- How many files changed?
|
||||
- Is this a targeted fix or broader refactoring?
|
||||
- Does this affect multiple features?
|
||||
|
||||
**3. Check for side effects:**
|
||||
- Could this break other features?
|
||||
- Are there edge cases not considered?
|
||||
|
||||
### Second Pass: Verify the Fix
|
||||
|
||||
<thinking>
|
||||
Evaluate the fix systematically:
|
||||
1. Does this fix address the root cause or just symptoms?
|
||||
2. Are there edge cases not covered?
|
||||
3. Could this break other functionality?
|
||||
4. Is the fix localized or does it ripple through the codebase?
|
||||
5. How do we prevent this bug from returning?
|
||||
</thinking>
|
||||
|
||||
**4. Code changes:**
|
||||
- Does the fix make sense?
|
||||
- Is it the simplest solution?
|
||||
- Any unnecessary changes included?
|
||||
|
||||
**5. Testing:**
|
||||
- Is there a regression test?
|
||||
- Does test verify the bug is fixed?
|
||||
- Are edge cases covered?
|
||||
|
||||
**6. Related code:**
|
||||
- Same pattern in other places that might have same bug?
|
||||
- Should other similar code be fixed too?
|
||||
|
||||
## What to CHECK
|
||||
|
||||
✅ **Root Cause Analysis**
|
||||
- Does the fix address the root cause or just symptoms?
|
||||
- Is the explanation in PR/commit clear?
|
||||
|
||||
✅ **Regression Testing**
|
||||
- Is there a new test that would fail without this fix?
|
||||
- Does test cover the reported bug scenario?
|
||||
- Are related edge cases tested?
|
||||
|
||||
✅ **Side Effects**
|
||||
- Could this break existing functionality?
|
||||
- Are there similar code paths that need checking?
|
||||
- Does this change behavior in unexpected ways?
|
||||
|
||||
✅ **Fix Scope**
|
||||
- Is the fix appropriately scoped (not too broad, not too narrow)?
|
||||
- Are all instances of the bug fixed?
|
||||
- Any related bugs discovered during investigation?
|
||||
|
||||
## What to SKIP
|
||||
|
||||
❌ **Full Architecture Review** - Unless fix reveals architectural problems
|
||||
❌ **Comprehensive Testing Review** - Focus on regression tests, not entire test suite
|
||||
❌ **Major Refactoring Suggestions** - Unless directly related to preventing similar bugs
|
||||
|
||||
## Red Flags
|
||||
|
||||
🚩 **No test for the bug** - How will we prevent regression?
|
||||
🚩 **Fix doesn't match root cause** - Is this fixing symptoms?
|
||||
🚩 **Broad changes beyond the bug** - Should this be split into separate PRs?
|
||||
🚩 **Similar patterns elsewhere** - Should those be fixed too?
|
||||
|
||||
## Key Questions to Ask
|
||||
|
||||
Use `reference/review-psychology.md` for phrasing:
|
||||
|
||||
- "Can we add a test that would fail without this fix?"
|
||||
- "I see this pattern in [other file] - does it have the same issue?"
|
||||
- "Is this fixing the root cause or masking the symptom?"
|
||||
- "Could this change affect [related feature]?"
|
||||
|
||||
## Prioritizing Findings
|
||||
|
||||
Use `reference/priority-framework.md` to classify findings as Critical/Important/Suggested/Optional.
|
||||
|
||||
## Output Format
|
||||
|
||||
Follow the format guidance from `SKILL.md` Step 5 (concise summary with critical issues only, detailed inline comments with `<details>` tags).
|
||||
|
||||
```markdown
|
||||
**Overall Assessment:** APPROVE / REQUEST CHANGES
|
||||
|
||||
**Critical Issues** (if any):
|
||||
- [One-line summary of each critical blocking issue with file:line reference]
|
||||
|
||||
See inline comments for all issue details.
|
||||
```
|
||||
|
||||
## Example Review
|
||||
|
||||
```markdown
|
||||
**Overall Assessment:** APPROVE
|
||||
|
||||
See inline comments for suggested improvements.
|
||||
```
|
||||
|
||||
**Inline comment examples:**
|
||||
|
||||
```
|
||||
**data/auth/BiometricRepository.kt:120** - SUGGESTED: Extract null handling
|
||||
|
||||
<details>
|
||||
<summary>Details</summary>
|
||||
|
||||
Root cause analysis: BiometricPrompt result was nullable but code assumed non-null, causing crash on cancellation (PM-12345).
|
||||
|
||||
Consider extracting null handling pattern:
|
||||
|
||||
\```kotlin
|
||||
private fun handleBiometricResult(result: BiometricPrompt.AuthenticationResult?): AuthResult {
|
||||
return result?.let { AuthResult.Success(it) } ?: AuthResult.Cancelled
|
||||
}
|
||||
\```
|
||||
|
||||
This pattern could be reused if we add other biometric auth points.
|
||||
</details>
|
||||
```
|
||||
|
||||
```
|
||||
**app/auth/BiometricViewModel.kt:89** - SUGGESTED: Add regression test
|
||||
|
||||
<details>
|
||||
<summary>Details</summary>
|
||||
|
||||
Add test for cancellation scenario to prevent regression:
|
||||
|
||||
\```kotlin
|
||||
@Test
|
||||
fun `when biometric cancelled then returns cancelled state`() = runTest {
|
||||
coEvery { repository.authenticate() } returns Result.failure(CancelledException())
|
||||
viewModel.onBiometricAuth()
|
||||
assertEquals(AuthState.Cancelled, viewModel.state.value)
|
||||
}
|
||||
\```
|
||||
|
||||
This prevents regression of the bug just fixed.
|
||||
</details>
|
||||
```
|
||||
166
.claude/skills/reviewing-changes/checklists/dependency-update.md
Normal file
166
.claude/skills/reviewing-changes/checklists/dependency-update.md
Normal file
@@ -0,0 +1,166 @@
|
||||
# Dependency Update Review Checklist
|
||||
|
||||
## Multi-Pass Strategy
|
||||
|
||||
### First Pass: Identify and Assess
|
||||
|
||||
<thinking>
|
||||
Before diving into details:
|
||||
1. Which dependencies were updated?
|
||||
2. What are the version changes? (patch, minor, major)
|
||||
3. Are any security-sensitive libraries involved? (crypto, auth, networking)
|
||||
4. Any pre-release versions (alpha, beta, RC)?
|
||||
5. What's the blast radius if something breaks?
|
||||
</thinking>
|
||||
|
||||
**1. Identify the change:**
|
||||
- Which library? Old version → New version?
|
||||
- Major (X.0.0), Minor (0.X.0), or Patch (0.0.X) version change?
|
||||
- Single dependency or multiple?
|
||||
|
||||
**2. Check compilation safety:**
|
||||
- Any imports in codebase that might break?
|
||||
- Any deprecated APIs we're currently using?
|
||||
- Check if this is a breaking change version
|
||||
|
||||
### Second Pass: Deep Analysis
|
||||
|
||||
<thinking>
|
||||
For each dependency update:
|
||||
1. What changes are in this release?
|
||||
2. Are there breaking changes?
|
||||
3. Are there security fixes?
|
||||
4. Do we use the affected APIs?
|
||||
5. How does this affect our codebase?
|
||||
</thinking>
|
||||
|
||||
**3. Review release notes** (if available):
|
||||
- Breaking changes mentioned?
|
||||
- Security fixes included?
|
||||
- New features we should know about?
|
||||
- Deprecations that affect our usage?
|
||||
|
||||
**4. Verify consistency:**
|
||||
- If updating androidx library, are related libraries updated consistently?
|
||||
- BOM (Bill of Materials) consistency if applicable?
|
||||
- Test dependencies updated alongside main dependencies?
|
||||
|
||||
## What to CHECK
|
||||
|
||||
✅ **Compilation Safety**
|
||||
- Look for API deprecations in our codebase
|
||||
- Check if import statements still valid
|
||||
- Major version bumps require extra scrutiny
|
||||
- Beta/alpha versions need stability assessment
|
||||
|
||||
✅ **Security Implications** (if applicable)
|
||||
- Security-related libraries (crypto, auth, networking)?
|
||||
- Check for CVEs addressed in release notes
|
||||
- Review security advisories for this library
|
||||
|
||||
✅ **Testing Implications**
|
||||
- Does this affect test utilities?
|
||||
- Are there breaking changes in test APIs?
|
||||
- Do existing tests still cover the same scenarios?
|
||||
|
||||
✅ **Changelog Review**
|
||||
- Read release notes for breaking changes
|
||||
- Note any behavioral changes
|
||||
- Check migration guides if major version
|
||||
|
||||
## What to SKIP
|
||||
|
||||
❌ **Full Architecture Review** - No code changed, patterns unchanged
|
||||
❌ **Code Style Review** - No code to review
|
||||
❌ **New Test Requirements** - Unless API changed significantly
|
||||
❌ **Security Deep-Dive** - Unless crypto/auth/networking library
|
||||
❌ **Performance Analysis** - Unless release notes mention performance changes
|
||||
|
||||
## Red Flags (Escalate to Full Review)
|
||||
|
||||
🚩 **Major version bump** (e.g., 1.x → 2.0) - Read `checklists/feature-addition.md`
|
||||
🚩 **Security/crypto library** - Read `reference/architectural-patterns.md` and `docs/ARCHITECTURE.md#security`
|
||||
🚩 **Breaking changes in release notes** - Read relevant code sections carefully
|
||||
🚩 **Multiple dependency updates at once** - Check for interaction risks
|
||||
🚩 **Beta/Alpha versions** - Assess stability concerns and rollback plan
|
||||
|
||||
If any red flags present, escalate to more comprehensive review using appropriate checklist.
|
||||
|
||||
## Prioritizing Findings
|
||||
|
||||
Use `reference/priority-framework.md` to classify findings as Critical/Important/Suggested/Optional.
|
||||
|
||||
## Output Format
|
||||
|
||||
Follow the format guidance from `SKILL.md` Step 5 (concise summary with critical issues only, detailed inline comments with `<details>` tags).
|
||||
|
||||
```markdown
|
||||
**Overall Assessment:** APPROVE / REQUEST CHANGES
|
||||
|
||||
**Critical Issues** (if any):
|
||||
- [One-line summary of each critical blocking issue with file:line reference]
|
||||
|
||||
See inline comments for all issue details.
|
||||
```
|
||||
|
||||
## Example Reviews
|
||||
|
||||
### Example 1: Simple Patch Version (No Critical Issues)
|
||||
|
||||
```markdown
|
||||
**Overall Assessment:** APPROVE
|
||||
|
||||
See inline comments for all issue details.
|
||||
```
|
||||
|
||||
**Inline comment example:**
|
||||
```
|
||||
**libs.versions.toml:45** - SUGGESTED: Beta version in production
|
||||
|
||||
<details>
|
||||
<summary>Details</summary>
|
||||
|
||||
androidx.credentials updated from 1.5.0 to 1.6.0-beta03
|
||||
|
||||
Monitor for stability issues - beta releases may have unexpected behavior in production.
|
||||
|
||||
Changelog: Adds support for additional credential types, internal bug fixes.
|
||||
</details>
|
||||
```
|
||||
|
||||
### Example 2: Major Version with Breaking Changes (With Critical Issues)
|
||||
|
||||
```markdown
|
||||
**Overall Assessment:** REQUEST CHANGES
|
||||
|
||||
**Critical Issues:**
|
||||
- Breaking API changes in Retrofit 3.0.0 (network/api/BitwardenApiService.kt)
|
||||
- Breaking API changes in Retrofit 3.0.0 (network/api/VaultApiService.kt)
|
||||
|
||||
See inline comments for migration details.
|
||||
```
|
||||
|
||||
**Inline comment example:**
|
||||
```
|
||||
**network/api/BitwardenApiService.kt:15** - CRITICAL: Breaking API changes
|
||||
|
||||
<details>
|
||||
<summary>Details and fix</summary>
|
||||
|
||||
Retrofit 3.0.0 removes `Call<T>` return type. Migration required:
|
||||
|
||||
\```kotlin
|
||||
// Before
|
||||
fun getUser(): Call<UserResponse>
|
||||
|
||||
// After
|
||||
suspend fun getUser(): Response<UserResponse>
|
||||
\```
|
||||
|
||||
Update all API service interfaces to use suspend functions, update call sites to use coroutines instead of enqueue/execute, and update tests accordingly.
|
||||
|
||||
Consider creating a separate PR for this migration due to scope.
|
||||
|
||||
Reference: https://github.com/square/retrofit/blob/master/CHANGELOG.md#version-300
|
||||
</details>
|
||||
```
|
||||
380
.claude/skills/reviewing-changes/checklists/feature-addition.md
Normal file
380
.claude/skills/reviewing-changes/checklists/feature-addition.md
Normal file
@@ -0,0 +1,380 @@
|
||||
# Feature Addition Review Checklist
|
||||
|
||||
## Multi-Pass Strategy
|
||||
|
||||
### First Pass: High-Level Assessment
|
||||
|
||||
<thinking>
|
||||
Before diving into details:
|
||||
1. What is this feature supposed to do?
|
||||
2. How does it fit into the existing architecture?
|
||||
3. What are the security implications?
|
||||
4. What's the scope? (files touched, modules affected)
|
||||
5. What are the highest-risk areas?
|
||||
</thinking>
|
||||
|
||||
**1. Understand the feature:**
|
||||
- Read PR description - what problem does this solve?
|
||||
- Identify user-facing changes vs internal changes
|
||||
- Note any security implications (auth, encryption, data handling)
|
||||
|
||||
**2. Scan file structure:**
|
||||
- Which modules affected? (app, data, network, ui, core?)
|
||||
- Are files organized correctly per module structure?
|
||||
- Any new public APIs introduced?
|
||||
|
||||
**3. Initial risk assessment:**
|
||||
- Does this touch sensitive data or security-critical paths?
|
||||
- Does this affect existing features or only add new ones?
|
||||
- Are there obvious compilation or null safety issues?
|
||||
|
||||
### Second Pass: Architecture Deep-Dive
|
||||
|
||||
<thinking>
|
||||
Verify architectural integrity:
|
||||
1. Does this follow MVVM + UDF pattern?
|
||||
2. Is Hilt DI used correctly?
|
||||
3. Is state management proper (StateFlow, immutability)?
|
||||
4. Are modules organized correctly?
|
||||
5. Is error handling robust (Result types)?
|
||||
</thinking>
|
||||
|
||||
**4. MVVM + UDF Pattern Compliance:**
|
||||
- ViewModels properly structured?
|
||||
- State management using StateFlow?
|
||||
- Business logic in correct layer?
|
||||
|
||||
**5. Dependency Injection:**
|
||||
- Hilt DI used correctly?
|
||||
- Dependencies injected, not manually instantiated?
|
||||
- Proper scoping applied?
|
||||
|
||||
**6. Module Organization:**
|
||||
- Code placed in correct modules?
|
||||
- No circular dependencies introduced?
|
||||
- Proper separation of concerns?
|
||||
|
||||
**7. Error Handling:**
|
||||
- Using Result types, not exception-based handling?
|
||||
- Errors propagated correctly through layers?
|
||||
|
||||
### Third Pass: Details and Quality
|
||||
|
||||
<thinking>
|
||||
Check quality and completeness:
|
||||
1. Is code quality high? (null safety, documentation, naming)
|
||||
2. Are tests comprehensive? (unit + integration)
|
||||
3. Are there edge cases not covered?
|
||||
4. Is documentation clear?
|
||||
5. Are there any code smells or anti-patterns?
|
||||
</thinking>
|
||||
|
||||
**8. Testing:**
|
||||
- Unit tests for ViewModels and repositories?
|
||||
- Test coverage for edge cases and error scenarios?
|
||||
- Tests verify behavior, not implementation?
|
||||
|
||||
**9. Code Quality:**
|
||||
- Null safety handled properly?
|
||||
- Public APIs have KDoc documentation?
|
||||
- Naming follows project conventions?
|
||||
|
||||
**10. Security:**
|
||||
- Sensitive data encrypted properly?
|
||||
- Authentication/authorization handled correctly?
|
||||
- Zero-knowledge architecture preserved?
|
||||
|
||||
## Architecture Review
|
||||
|
||||
### MVVM Pattern Compliance
|
||||
|
||||
Read `reference/architectural-patterns.md` for detailed patterns.
|
||||
|
||||
**ViewModels must:**
|
||||
- Use `@HiltViewModel` annotation
|
||||
- Use `@Inject constructor`
|
||||
- Expose `StateFlow<T>`, NOT `MutableStateFlow<T>` publicly
|
||||
- Delegate business logic to Repository/Manager
|
||||
- Avoid direct Android framework dependencies (except ViewModel, SavedStateHandle)
|
||||
|
||||
**Common Violations:**
|
||||
```kotlin
|
||||
// ❌ BAD - Exposes mutable state
|
||||
class FeatureViewModel @Inject constructor() : ViewModel() {
|
||||
val state: MutableStateFlow<State> = MutableStateFlow(State.Initial)
|
||||
}
|
||||
|
||||
// ✅ GOOD - Exposes immutable state
|
||||
class FeatureViewModel @Inject constructor() : ViewModel() {
|
||||
private val _state = MutableStateFlow<State>(State.Initial)
|
||||
val state: StateFlow<State> = _state.asStateFlow()
|
||||
}
|
||||
|
||||
// ❌ BAD - Business logic in ViewModel
|
||||
fun onSubmit() {
|
||||
val encrypted = encryptionManager.encrypt(password) // Should be in Repository
|
||||
_state.value = State.Success
|
||||
}
|
||||
|
||||
// ✅ GOOD - Business logic in Repository, state updated via internal event
|
||||
fun onSubmit() {
|
||||
viewModelScope.launch {
|
||||
// The result of the async operation is captured
|
||||
val result = repository.submitData(password)
|
||||
// A single event is sent with the result, not updating state directly
|
||||
sendAction(FeatureAction.Internal.SubmissionComplete(result))
|
||||
}
|
||||
}
|
||||
|
||||
// The ViewModel has a handler that processes the internal event
|
||||
private fun handleInternalAction(action: FeatureAction.Internal) {
|
||||
when (action) {
|
||||
is FeatureAction.Internal.SubmissionComplete -> {
|
||||
// The event handler evaluates the result and updates state
|
||||
action.result.fold(
|
||||
onSuccess = { _state.value = State.Success },
|
||||
onFailure = { _state.value = State.Error(it) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**UI Layer must:**
|
||||
- Only observe state, never modify
|
||||
- Pass user actions as events to ViewModel
|
||||
- Contain no business logic
|
||||
- Use existing UI components from `:ui` module where possible
|
||||
|
||||
### Hilt Dependency Injection
|
||||
|
||||
Reference: `docs/ARCHITECTURE.md#dependency-injection`
|
||||
|
||||
**Required Patterns:**
|
||||
- ViewModels: `@HiltViewModel` + `@Inject constructor`
|
||||
- Repositories: `@Inject constructor` on implementation
|
||||
- Inject interfaces, not concrete implementations
|
||||
- Modules must provide proper scoping (`@Singleton`, `@ViewModelScoped`)
|
||||
|
||||
**Common Violations:**
|
||||
```kotlin
|
||||
// ❌ BAD - Manual instantiation
|
||||
class FeatureViewModel : ViewModel() {
|
||||
private val repository = FeatureRepositoryImpl()
|
||||
}
|
||||
|
||||
// ✅ GOOD - Injected interface
|
||||
@HiltViewModel
|
||||
class FeatureViewModel @Inject constructor(
|
||||
private val repository: FeatureRepository // Interface, not implementation
|
||||
) : ViewModel()
|
||||
|
||||
// ❌ BAD - Injecting implementation
|
||||
class FeatureViewModel @Inject constructor(
|
||||
private val repository: FeatureRepositoryImpl // Should inject interface
|
||||
)
|
||||
|
||||
// ✅ GOOD - Interface injection
|
||||
class FeatureViewModel @Inject constructor(
|
||||
private val repository: FeatureRepository // Interface
|
||||
)
|
||||
```
|
||||
|
||||
### Module Organization
|
||||
|
||||
Reference: `docs/ARCHITECTURE.md#module-structure`
|
||||
|
||||
**Correct Placement:**
|
||||
- `:core` - Shared utilities (cryptography, analytics, logging)
|
||||
- `:data` - Repositories, database, domain models
|
||||
- `:network` - API clients, network utilities
|
||||
- `:ui` - Reusable Compose components, theme
|
||||
- `:app` - Feature screens, ViewModels, navigation
|
||||
- `:authenticator` - Authenticator app (separate from password manager)
|
||||
|
||||
**Check:**
|
||||
- UI code in `:ui` or `:app` modules
|
||||
- Data models in `:data`
|
||||
- Network clients in `:network`
|
||||
- No circular dependencies between modules
|
||||
|
||||
### Error Handling
|
||||
|
||||
Reference: `docs/ARCHITECTURE.md#error-handling`
|
||||
|
||||
**Required Pattern - Use Result types:**
|
||||
```kotlin
|
||||
// ✅ GOOD - Result type
|
||||
suspend fun fetchData(): Result<Data> = runCatching {
|
||||
apiService.getData()
|
||||
}
|
||||
|
||||
// ViewModel handles Result
|
||||
repository.fetchData().fold(
|
||||
onSuccess = { data -> _state.value = State.Success(data) },
|
||||
onFailure = { error -> _state.value = State.Error(error) }
|
||||
)
|
||||
|
||||
// ❌ BAD - Exception-based in business logic
|
||||
suspend fun fetchData(): Data {
|
||||
try {
|
||||
return apiService.getData()
|
||||
} catch (e: Exception) {
|
||||
throw FeatureException(e) // Don't throw in business logic
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Security Review
|
||||
|
||||
Reference: `docs/ARCHITECTURE.md#security`
|
||||
|
||||
**Critical Security Checks:**
|
||||
|
||||
- **Sensitive data encrypted**: Passwords, keys, tokens use Android Keystore or EncryptedSharedPreferences
|
||||
- **No plaintext secrets**: No passwords/keys in logs, memory dumps, or SharedPreferences
|
||||
- **Input validation**: All user-provided data validated and sanitized
|
||||
- **Authentication tokens**: Securely stored and transmitted
|
||||
- **Zero-knowledge architecture**: Encryption happens client-side, server never sees plaintext
|
||||
|
||||
**Red Flags:**
|
||||
```kotlin
|
||||
// ❌ CRITICAL - Plaintext storage
|
||||
sharedPreferences.edit {
|
||||
putString("pin", userPin) // Must use EncryptedSharedPreferences
|
||||
}
|
||||
|
||||
// ❌ CRITICAL - Logging sensitive data
|
||||
Log.d("Auth", "Password: $password") // Never log sensitive data
|
||||
|
||||
// ❌ CRITICAL - Weak encryption
|
||||
val cipher = Cipher.getInstance("DES") // Use AES-256-GCM
|
||||
|
||||
// ✅ GOOD - Keystore encryption
|
||||
val encryptedData = keystoreManager.encrypt(sensitiveData)
|
||||
secureStorage.store(encryptedData)
|
||||
```
|
||||
|
||||
**If security concerns found, classify as CRITICAL using `reference/priority-framework.md`**
|
||||
|
||||
## Testing Review
|
||||
|
||||
Reference: `reference/testing-patterns.md`
|
||||
|
||||
**Required Test Coverage:**
|
||||
|
||||
- **ViewModels**: Unit tests for state transitions, actions, error scenarios
|
||||
- **Repositories**: Unit tests for data transformations, error handling
|
||||
- **Business logic**: Unit tests for complex algorithms, calculations
|
||||
- **Edge cases**: Null inputs, empty states, network failures, concurrent operations
|
||||
|
||||
**Test Quality:**
|
||||
```kotlin
|
||||
// ✅ GOOD - Tests behavior
|
||||
@Test
|
||||
fun `when login succeeds then state updates to success`() = runTest {
|
||||
val viewModel = LoginViewModel(mockRepository)
|
||||
|
||||
coEvery { mockRepository.login(any(), any()) } returns Result.success(User())
|
||||
|
||||
viewModel.onLoginClicked("user", "pass")
|
||||
|
||||
viewModel.state.test {
|
||||
assertEquals(LoginState.Success, awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
// ❌ BAD - Tests implementation
|
||||
@Test
|
||||
fun `repository is called with correct parameters`() {
|
||||
// This is testing internal implementation, not behavior
|
||||
}
|
||||
```
|
||||
|
||||
**Testing Frameworks:**
|
||||
- JUnit 5 for test structure
|
||||
- MockK for mocking
|
||||
- Turbine for Flow testing
|
||||
- Kotlinx-coroutines-test for coroutine testing
|
||||
|
||||
## Code Quality
|
||||
|
||||
### Null Safety
|
||||
|
||||
- No `!!` (non-null assertion) without clear safety guarantee
|
||||
- Platform types (from Java) handled with explicit nullability
|
||||
- Nullable types have proper null checks or use safe operators (`?.`, `?:`)
|
||||
|
||||
```kotlin
|
||||
// ❌ BAD - Unsafe assertion
|
||||
val result = apiService.getData()!! // Could crash
|
||||
|
||||
// ✅ GOOD - Safe handling
|
||||
val result = apiService.getData() ?: return State.Error("No data")
|
||||
|
||||
// ❌ BAD - Platform type unchecked
|
||||
val intent: Intent = getIntent() // Could be null from Java
|
||||
intent.getStringExtra("key") // Potential NPE
|
||||
|
||||
// ✅ GOOD - Explicit nullability
|
||||
val intent: Intent? = getIntent()
|
||||
intent?.getStringExtra("key")
|
||||
```
|
||||
|
||||
### Documentation
|
||||
|
||||
- **Public APIs**: Have KDoc comments explaining purpose, parameters, return values
|
||||
- **Complex algorithms**: Explained in comments
|
||||
- **Non-obvious behavior**: Documented with rationale
|
||||
|
||||
```kotlin
|
||||
// ✅ GOOD - Documented public API
|
||||
/**
|
||||
* Encrypts the given data using AES-256-GCM with a key from Android Keystore.
|
||||
*
|
||||
* @param plaintext The data to encrypt
|
||||
* @return Result containing encrypted data or encryption error
|
||||
*/
|
||||
suspend fun encrypt(plaintext: ByteArray): Result<EncryptedData>
|
||||
```
|
||||
|
||||
### Style Compliance
|
||||
|
||||
Reference: `docs/STYLE_AND_BEST_PRACTICES.md`
|
||||
|
||||
Only flag style issues if:
|
||||
- Not caught by linters (Detekt, ktlint)
|
||||
- Have architectural implications
|
||||
- Significantly impact readability
|
||||
|
||||
Skip minor formatting (spaces, line breaks, etc.) - linters handle this.
|
||||
|
||||
## Prioritizing Findings
|
||||
|
||||
Use `reference/priority-framework.md` to classify findings as Critical/Important/Suggested/Optional.
|
||||
|
||||
## Providing Feedback
|
||||
|
||||
Use `reference/review-psychology.md` for phrasing guidance.
|
||||
|
||||
**Key principles:**
|
||||
- **Ask questions** for design decisions: "Can we use the existing BitwardenTextField component here?"
|
||||
- **Be prescriptive** for clear violations: "Change MutableStateFlow to StateFlow (MVVM pattern requirement)"
|
||||
- **Explain rationale**: "This exposes mutable state, violating unidirectional data flow"
|
||||
- **Use I-statements**: "It's hard for me to understand this logic without comments"
|
||||
- **Avoid condescension**: Don't use "just", "simply", "obviously"
|
||||
|
||||
## Output Format
|
||||
|
||||
Follow the format guidance from `SKILL.md` Step 5 (concise summary with critical issues only, detailed inline comments with `<details>` tags).
|
||||
|
||||
See `examples/review-outputs.md` for comprehensive feature review example.
|
||||
|
||||
```markdown
|
||||
**Overall Assessment:** APPROVE / REQUEST CHANGES
|
||||
|
||||
**Critical Issues** (if any):
|
||||
- [One-line summary of each critical blocking issue with file:line reference]
|
||||
|
||||
See inline comments for all issue details.
|
||||
```
|
||||
250
.claude/skills/reviewing-changes/checklists/infrastructure.md
Normal file
250
.claude/skills/reviewing-changes/checklists/infrastructure.md
Normal file
@@ -0,0 +1,250 @@
|
||||
# Infrastructure Review Checklist
|
||||
|
||||
## Multi-Pass Strategy
|
||||
|
||||
### First Pass: Understand the Change
|
||||
|
||||
<thinking>
|
||||
Assess infrastructure change:
|
||||
1. What problem does this solve?
|
||||
2. Does this affect production builds, CI/CD, or dev workflow?
|
||||
3. What's the risk if this breaks?
|
||||
4. Can this be tested before merge?
|
||||
5. What's the rollback plan?
|
||||
</thinking>
|
||||
|
||||
**1. Identify the goal:**
|
||||
- What problem does this solve?
|
||||
- Is this optimization, fix, or new capability?
|
||||
- What's the expected impact?
|
||||
|
||||
**2. Assess risk:**
|
||||
- Does this affect production builds?
|
||||
- Could this break CI/CD pipelines?
|
||||
- Impact on developer workflow?
|
||||
|
||||
**3. Performance implications:**
|
||||
- Will builds be faster or slower?
|
||||
- CI time impact?
|
||||
- Resource usage changes?
|
||||
|
||||
### Second Pass: Verify Implementation
|
||||
|
||||
<thinking>
|
||||
Verify configuration and impact:
|
||||
1. Is the configuration syntax valid?
|
||||
2. Are secrets/credentials handled securely?
|
||||
3. What's the impact on build times and CI performance?
|
||||
4. How will this affect the team's workflow?
|
||||
5. Is there adequate testing/validation?
|
||||
</thinking>
|
||||
|
||||
**4. Configuration correctness:**
|
||||
- Syntax valid?
|
||||
- References correct?
|
||||
- Secrets/credentials handled securely?
|
||||
|
||||
**5. Impact analysis:**
|
||||
- What workflows/builds are affected?
|
||||
- Rollback plan if this breaks?
|
||||
- Documentation for team?
|
||||
|
||||
**6. Testing strategy:**
|
||||
- How can this be tested before merge?
|
||||
- Canary/gradual rollout possible?
|
||||
- Monitoring for issues post-merge?
|
||||
|
||||
## What to CHECK
|
||||
|
||||
✅ **Configuration Correctness**
|
||||
- YAML/Groovy syntax valid
|
||||
- File references correct
|
||||
- Version numbers/tags valid
|
||||
- Conditional logic sound
|
||||
|
||||
✅ **Security**
|
||||
- No hardcoded secrets or credentials
|
||||
- GitHub secrets used properly
|
||||
- Permissions appropriately scoped
|
||||
- No sensitive data in logs
|
||||
|
||||
✅ **Performance Impact**
|
||||
- Build time implications understood
|
||||
- CI queue time impact assessed
|
||||
- Resource usage reasonable
|
||||
|
||||
✅ **Rollback Plan**
|
||||
- Can this be reverted easily?
|
||||
- Dependencies on other changes?
|
||||
- Gradual rollout possible?
|
||||
|
||||
✅ **Documentation**
|
||||
- Changes documented for team?
|
||||
- README or CONTRIBUTING updated?
|
||||
- Breaking changes clearly noted?
|
||||
|
||||
## What to SKIP
|
||||
|
||||
❌ **Bikeshedding Configuration** - Unless clear performance/maintenance benefit
|
||||
❌ **Over-Optimization** - Unless current system has proven problems
|
||||
❌ **Suggesting Major Rewrites** - Unless current approach is fundamentally broken
|
||||
|
||||
## Red Flags
|
||||
|
||||
🚩 **Hardcoded secrets** - Use GitHub secrets or secure storage
|
||||
🚩 **No rollback plan** - Critical infrastructure should be revertible
|
||||
🚩 **Untested changes** - CI changes should be validated
|
||||
🚩 **Breaking changes without notice** - Team needs advance warning
|
||||
🚩 **Performance regression** - Builds shouldn't get significantly slower
|
||||
|
||||
## Key Questions to Ask
|
||||
|
||||
Use `reference/review-psychology.md` for phrasing:
|
||||
|
||||
- "What's the rollback plan if this breaks CI?"
|
||||
- "Can we test this on a feature branch before main?"
|
||||
- "Will this impact build times? By how much?"
|
||||
- "Should this be documented in CONTRIBUTING.md?"
|
||||
|
||||
## Common Infrastructure Patterns
|
||||
|
||||
### GitHub Actions
|
||||
|
||||
```yaml
|
||||
# ✅ GOOD - Secure, clear, tested
|
||||
name: Build and Test
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30 # Prevent runaway builds
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run tests
|
||||
env:
|
||||
API_KEY: ${{ secrets.API_KEY }} # Secure secret usage
|
||||
run: ./gradlew test
|
||||
|
||||
# ❌ BAD - Insecure, unclear
|
||||
name: Build
|
||||
on: push # Too broad, runs on all branches
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
# No timeout - could run forever
|
||||
steps:
|
||||
- run: |
|
||||
export API_KEY="hardcoded_key_here" # Hardcoded secret!
|
||||
./gradlew test
|
||||
```
|
||||
|
||||
### Gradle Configuration
|
||||
|
||||
```kotlin
|
||||
// ✅ GOOD - Clear, maintainable
|
||||
dependencies {
|
||||
implementation(libs.androidx.core.ktx) // Version catalog
|
||||
implementation(libs.hilt.android)
|
||||
|
||||
testImplementation(libs.junit5)
|
||||
testImplementation(libs.mockk)
|
||||
}
|
||||
|
||||
// ❌ BAD - Hardcoded versions
|
||||
dependencies {
|
||||
implementation("androidx.core:core-ktx:1.12.0") // Hardcoded version
|
||||
implementation("com.google.dagger:hilt-android:2.48")
|
||||
}
|
||||
```
|
||||
|
||||
### Build Optimization
|
||||
|
||||
```kotlin
|
||||
// ✅ GOOD - Parallel, cached
|
||||
tasks.register("checkAll") {
|
||||
dependsOn("detekt", "ktlintCheck", "testStandardDebug")
|
||||
group = "verification"
|
||||
description = "Run all checks in parallel"
|
||||
|
||||
// Enable caching for faster builds
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
|
||||
// ❌ BAD - Sequential, no caching
|
||||
tasks.register("checkAll") {
|
||||
doLast {
|
||||
exec { commandLine("./gradlew", "detekt") }
|
||||
exec { commandLine("./gradlew", "ktlintCheck") } // Sequential
|
||||
exec { commandLine("./gradlew", "test") }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Prioritizing Findings
|
||||
|
||||
Use `reference/priority-framework.md` to classify findings as Critical/Important/Suggested/Optional.
|
||||
|
||||
## Output Format
|
||||
|
||||
Follow the format guidance from `SKILL.md` Step 5 (concise summary with critical issues only, detailed inline comments with `<details>` tags).
|
||||
|
||||
```markdown
|
||||
**Overall Assessment:** APPROVE / REQUEST CHANGES
|
||||
|
||||
**Critical Issues** (if any):
|
||||
- [One-line summary of each critical blocking issue with file:line reference]
|
||||
|
||||
See inline comments for all issue details.
|
||||
```
|
||||
|
||||
## Example Review
|
||||
|
||||
```markdown
|
||||
## Summary
|
||||
Optimizes CI build by parallelizing test execution and caching dependencies
|
||||
|
||||
Impact: Estimated 40% reduction in CI time (12 min → 7 min per build)
|
||||
|
||||
## Critical Issues
|
||||
None
|
||||
|
||||
## Suggested Improvements
|
||||
|
||||
**.github/workflows/build.yml:23** - Add timeout for safety
|
||||
```yaml
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30 # Prevent builds from hanging
|
||||
steps:
|
||||
# ...
|
||||
```
|
||||
This prevents runaway builds if something goes wrong.
|
||||
|
||||
**.github/workflows/build.yml:45** - Consider matrix strategy for module tests
|
||||
Can we run module tests in parallel using a matrix strategy?
|
||||
```yaml
|
||||
strategy:
|
||||
matrix:
|
||||
module: [app, data, network, ui]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: ./gradlew :${{ matrix.module }}:test
|
||||
```
|
||||
This could further reduce CI time.
|
||||
|
||||
**build.gradle.kts:12** - Document caching strategy
|
||||
Can we add a comment explaining the caching configuration?
|
||||
Future maintainers will appreciate understanding why these specific cache keys are used.
|
||||
|
||||
## Rollback Plan
|
||||
If CI breaks:
|
||||
- Revert commit: `git revert [commit-hash]`
|
||||
- Previous workflow available at: `.github/workflows/build.yml@main^`
|
||||
- Monitor CI times at: https://github.com/[org]/[repo]/actions
|
||||
```
|
||||
294
.claude/skills/reviewing-changes/checklists/refactoring.md
Normal file
294
.claude/skills/reviewing-changes/checklists/refactoring.md
Normal file
@@ -0,0 +1,294 @@
|
||||
# Refactoring Review Checklist
|
||||
|
||||
## Multi-Pass Strategy
|
||||
|
||||
### First Pass: Understand the Refactoring
|
||||
|
||||
<thinking>
|
||||
Analyze the refactoring scope:
|
||||
1. What pattern is being improved?
|
||||
2. Why is this refactoring needed?
|
||||
3. Does this change behavior or just structure?
|
||||
4. What's the scope? (files affected, migration completeness)
|
||||
5. What are the risks if something breaks?
|
||||
</thinking>
|
||||
|
||||
**1. Understand the goal:**
|
||||
- What pattern is being improved?
|
||||
- Why is this refactoring needed?
|
||||
- What's the scope of changes?
|
||||
|
||||
**2. Assess completeness:**
|
||||
- Are all instances refactored or just some?
|
||||
- Are there related areas that should also change?
|
||||
- Is the migration complete or partial?
|
||||
|
||||
**3. Risk assessment:**
|
||||
- Does this change behavior?
|
||||
- How many files affected?
|
||||
- Are tests updated to reflect changes?
|
||||
|
||||
### Second Pass: Verify Consistency
|
||||
|
||||
<thinking>
|
||||
Verify refactoring quality:
|
||||
1. Is the new pattern applied consistently throughout?
|
||||
2. Are there missed instances of the old pattern?
|
||||
3. Do tests still pass with same behavior?
|
||||
4. Is the migration complete or partial?
|
||||
5. Does this introduce any new issues?
|
||||
</thinking>
|
||||
|
||||
**4. Pattern consistency:**
|
||||
- Is the new pattern applied consistently throughout?
|
||||
- Are there missed instances of the old pattern?
|
||||
- Does this match established project patterns?
|
||||
|
||||
**5. Migration completeness:**
|
||||
- Old pattern fully removed or deprecated?
|
||||
- All usages updated?
|
||||
- Documentation updated?
|
||||
|
||||
**6. Test coverage:**
|
||||
- Do tests still pass?
|
||||
- Are tests refactored to match?
|
||||
- Does behavior remain unchanged?
|
||||
|
||||
## What to CHECK
|
||||
|
||||
✅ **Pattern Consistency**
|
||||
- New pattern applied consistently across all touched code
|
||||
- Follows established project patterns (MVVM, DI, error handling)
|
||||
- No mix of old and new patterns
|
||||
|
||||
✅ **Migration Completeness**
|
||||
- All instances of old pattern updated?
|
||||
- Deprecated methods removed or marked @Deprecated?
|
||||
- Related code also updated (tests, docs)?
|
||||
|
||||
✅ **Behavior Preservation**
|
||||
- Refactoring doesn't change behavior
|
||||
- Tests still pass
|
||||
- Edge cases still handled
|
||||
|
||||
✅ **Deprecation Strategy** (if applicable)
|
||||
- Old APIs marked @Deprecated with migration guidance
|
||||
- Replacement clearly documented
|
||||
- Timeline for removal specified
|
||||
|
||||
## What to SKIP
|
||||
|
||||
❌ **Suggesting Additional Refactorings** - Unless directly related to current changes
|
||||
❌ **Scope Creep** - Don't request refactoring of untouched code
|
||||
❌ **Perfection** - Better code is better than perfect code
|
||||
|
||||
## Red Flags
|
||||
|
||||
🚩 **Incomplete migration** - Mix of old and new patterns
|
||||
🚩 **Behavior changes** - Refactoring shouldn't change behavior
|
||||
🚩 **Broken tests** - Tests should be updated to match refactoring
|
||||
🚩 **Undocumented pattern** - New pattern should be clear to team
|
||||
|
||||
## Key Questions to Ask
|
||||
|
||||
Use `reference/review-psychology.md` for phrasing:
|
||||
|
||||
- "I see the old pattern still used in [file:line] - should that be updated too?"
|
||||
- "Can we add @Deprecated to the old method with migration guidance?"
|
||||
- "How do we ensure this behavior remains the same?"
|
||||
- "Should this pattern be documented in ARCHITECTURE.md?"
|
||||
|
||||
## Common Refactoring Patterns
|
||||
|
||||
### Extract Interface/Repository
|
||||
|
||||
```kotlin
|
||||
// ✅ GOOD - Complete migration
|
||||
interface FeatureRepository {
|
||||
suspend fun getData(): Result<Data>
|
||||
}
|
||||
|
||||
class FeatureRepositoryImpl @Inject constructor(
|
||||
private val apiService: FeatureApiService
|
||||
) : FeatureRepository {
|
||||
override suspend fun getData(): Result<Data> = runCatching {
|
||||
apiService.fetchData()
|
||||
}
|
||||
}
|
||||
|
||||
// All usages updated to inject interface
|
||||
class FeatureViewModel @Inject constructor(
|
||||
private val repository: FeatureRepository // Interface
|
||||
) : ViewModel()
|
||||
|
||||
// ❌ BAD - Incomplete migration
|
||||
// Some files still inject FeatureRepositoryImpl directly
|
||||
```
|
||||
|
||||
### Modernize Error Handling
|
||||
|
||||
```kotlin
|
||||
// ✅ GOOD - Complete migration
|
||||
// Old exception-based removed
|
||||
suspend fun fetchData(): Result<Data> = runCatching {
|
||||
apiService.getData()
|
||||
}
|
||||
|
||||
// All call sites updated
|
||||
repository.fetchData().fold(
|
||||
onSuccess = { /* handle */ },
|
||||
onFailure = { /* handle */ }
|
||||
)
|
||||
|
||||
// ❌ BAD - Mixed patterns
|
||||
// Some functions use Result, others still throw exceptions
|
||||
```
|
||||
|
||||
### Extract Reusable Component
|
||||
|
||||
```kotlin
|
||||
// ✅ GOOD - Complete extraction
|
||||
// Component moved to :ui module
|
||||
@Composable
|
||||
fun BitwardenButton(
|
||||
text: String,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
)
|
||||
|
||||
// All usages updated to use new component
|
||||
// Old inline button implementations removed
|
||||
|
||||
// ❌ BAD - Incomplete extraction
|
||||
// Some screens use new component, others still have inline implementation
|
||||
```
|
||||
|
||||
## Prioritizing Findings
|
||||
|
||||
Use `reference/priority-framework.md` to classify findings as Critical/Important/Suggested/Optional.
|
||||
|
||||
## Output Format
|
||||
|
||||
Follow the format guidance from `SKILL.md` Step 5 (concise summary with critical issues only, detailed inline comments with `<details>` tags).
|
||||
|
||||
```markdown
|
||||
**Overall Assessment:** APPROVE / REQUEST CHANGES
|
||||
|
||||
**Critical Issues** (if any):
|
||||
- [One-line summary of each critical blocking issue with file:line reference]
|
||||
|
||||
See inline comments for all issue details.
|
||||
```
|
||||
|
||||
## Example Reviews
|
||||
|
||||
### Example 1: Refactoring with Incomplete Migration
|
||||
|
||||
**Context**: Refactoring authentication to Repository pattern, but one ViewModel still uses old pattern
|
||||
|
||||
**Summary Comment:**
|
||||
```markdown
|
||||
**Overall Assessment:** REQUEST CHANGES
|
||||
|
||||
**Critical Issues:**
|
||||
- Incomplete migration (app/vault/VaultViewModel.kt:89)
|
||||
|
||||
See inline comments for details.
|
||||
```
|
||||
|
||||
**Inline Comment 1** (on `app/vault/VaultViewModel.kt:89`):
|
||||
```markdown
|
||||
**IMPORTANT**: Incomplete migration
|
||||
|
||||
<details>
|
||||
<summary>Details and fix</summary>
|
||||
|
||||
This ViewModel still injects AuthManager directly. Should it use AuthRepository like the other 11 ViewModels?
|
||||
|
||||
\```kotlin
|
||||
// Current (old pattern)
|
||||
class VaultViewModel @Inject constructor(
|
||||
private val authManager: AuthManager
|
||||
)
|
||||
|
||||
// Should be (new pattern)
|
||||
class VaultViewModel @Inject constructor(
|
||||
private val authRepository: AuthRepository
|
||||
)
|
||||
\```
|
||||
|
||||
This is the only ViewModel still using the old pattern.
|
||||
</details>
|
||||
```
|
||||
|
||||
**Inline Comment 2** (on `data/auth/AuthManager.kt:1`):
|
||||
```markdown
|
||||
**SUGGESTED**: Add deprecation notice
|
||||
|
||||
<details>
|
||||
<summary>Details</summary>
|
||||
|
||||
Can we add @Deprecated to AuthManager to guide future development?
|
||||
|
||||
\```kotlin
|
||||
@Deprecated(
|
||||
message = "Use AuthRepository interface instead",
|
||||
replaceWith = ReplaceWith("AuthRepository"),
|
||||
level = DeprecationLevel.WARNING
|
||||
)
|
||||
class AuthManager @Inject constructor(...)
|
||||
\```
|
||||
|
||||
This helps prevent new code from using the old pattern.
|
||||
</details>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Example 2: Clean Refactoring (No Issues)
|
||||
|
||||
**Context**: Refactoring with complete migration, all patterns followed correctly, tests passing
|
||||
|
||||
**Review Comment:**
|
||||
```markdown
|
||||
**Overall Assessment:** APPROVE
|
||||
|
||||
Clean refactoring moving ExitManager to :ui module. Follows established patterns, eliminates duplication, tests updated correctly.
|
||||
```
|
||||
|
||||
**Token count:** ~30 tokens (vs ~800 for verbose format)
|
||||
|
||||
**Why this works:**
|
||||
- 3 lines total
|
||||
- Clear approval decision
|
||||
- Briefly notes what was done
|
||||
- No elaborate sections, checkmarks, or excessive praise
|
||||
- Author gets immediate green light to merge
|
||||
|
||||
**What NOT to do for clean refactorings:**
|
||||
```markdown
|
||||
❌ DO NOT create these sections:
|
||||
|
||||
## Summary
|
||||
This PR successfully refactors ExitManager into shared code...
|
||||
|
||||
## Key Strengths
|
||||
- ✅ Follows established module organization patterns
|
||||
- ✅ Removes code duplication between apps
|
||||
- ✅ Improves test coverage
|
||||
- ✅ Maintains consistent behavior
|
||||
[...20 more checkmarks...]
|
||||
|
||||
## Code Quality & Architecture
|
||||
**Architectural Compliance:** ✅
|
||||
- Correctly places manager in :ui module
|
||||
- Follows established pattern for UI-layer managers
|
||||
[...detailed analysis...]
|
||||
|
||||
## Changes
|
||||
- ✅ Moved ExitManager interface from app → ui module
|
||||
- ✅ Moved ExitManagerImpl from app → ui module
|
||||
[...listing every file...]
|
||||
```
|
||||
|
||||
This is excessive. **For clean PRs: 2-3 lines maximum.**
|
||||
233
.claude/skills/reviewing-changes/checklists/ui-refinement.md
Normal file
233
.claude/skills/reviewing-changes/checklists/ui-refinement.md
Normal file
@@ -0,0 +1,233 @@
|
||||
# UI Refinement Review Checklist
|
||||
|
||||
## Multi-Pass Strategy
|
||||
|
||||
### First Pass: Visual Changes
|
||||
|
||||
<thinking>
|
||||
Analyze the UI changes:
|
||||
1. What visual/UX problem is being solved?
|
||||
2. Are there designs or screenshots to reference?
|
||||
3. Is this affecting existing screens or new ones?
|
||||
4. What's the scope of visual changes?
|
||||
5. Are design tokens (colors, spacing, typography) being used correctly?
|
||||
</thinking>
|
||||
|
||||
**1. Understand the changes:**
|
||||
- What visual/UX problem is being solved?
|
||||
- Are there designs or screenshots to reference?
|
||||
- Is this a bug fix or enhancement?
|
||||
|
||||
**2. Component usage:**
|
||||
- Using existing components from `:ui` module?
|
||||
- Any new custom components created?
|
||||
- Could existing components be reused?
|
||||
|
||||
### Second Pass: Implementation Review
|
||||
|
||||
<thinking>
|
||||
Check implementation quality:
|
||||
1. Are Compose best practices followed?
|
||||
2. Is state hoisting applied correctly?
|
||||
3. Are existing components reused where possible?
|
||||
4. Is accessibility properly handled?
|
||||
5. Does this follow design system patterns?
|
||||
</thinking>
|
||||
|
||||
**3. Compose best practices:**
|
||||
- Composables properly structured?
|
||||
- State hoisted correctly?
|
||||
- Preview composables included?
|
||||
|
||||
**4. Accessibility:**
|
||||
- Content descriptions for images/icons?
|
||||
- Semantic properties for screen readers?
|
||||
- Touch targets meet minimum size (48dp)?
|
||||
|
||||
**5. Design consistency:**
|
||||
- Using theme colors, spacing, typography?
|
||||
- Consistent with other screens?
|
||||
- Responsive to different screen sizes?
|
||||
|
||||
## What to CHECK
|
||||
|
||||
✅ **Compose Best Practices**
|
||||
- Composables are stateless where possible
|
||||
- State hoisting follows patterns
|
||||
- Side effects (LaunchedEffect, DisposableEffect) used correctly
|
||||
- Preview composables provided for development
|
||||
|
||||
✅ **Component Reuse**
|
||||
- Using existing BitwardenButton, BitwardenTextField, etc.?
|
||||
- Could custom UI be replaced with existing components?
|
||||
- New reusable components placed in `:ui` module?
|
||||
|
||||
✅ **Accessibility**
|
||||
- `contentDescription` for icons and images
|
||||
- `semantics` for custom interactions
|
||||
- Sufficient contrast ratios
|
||||
- Touch targets ≥ 48dp minimum
|
||||
|
||||
✅ **Design Consistency**
|
||||
- Using `BitwardenTheme` colors (not hardcoded)
|
||||
- Using `BitwardenTheme` spacing (16.dp, 8.dp, etc.)
|
||||
- Using `BitwardenTheme` typography styles
|
||||
- Consistent with existing screen patterns
|
||||
|
||||
✅ **Responsive Design**
|
||||
- Handles different screen sizes?
|
||||
- Scrollable content where appropriate?
|
||||
- Landscape orientation considered?
|
||||
|
||||
## What to SKIP
|
||||
|
||||
❌ **Deep Architecture Review** - Unless ViewModel changes are substantial
|
||||
❌ **Business Logic Review** - Focus is on presentation, not logic
|
||||
❌ **Security Review** - Unless UI exposes sensitive data improperly
|
||||
|
||||
## Red Flags
|
||||
|
||||
🚩 **Duplicating existing components** - Should reuse from `:ui` module
|
||||
🚩 **Hardcoded colors/dimensions** - Should use theme
|
||||
🚩 **Missing accessibility properties** - Critical for screen readers
|
||||
🚩 **State management in UI** - Should be hoisted to ViewModel
|
||||
|
||||
## Key Questions to Ask
|
||||
|
||||
Use `reference/review-psychology.md` for phrasing:
|
||||
|
||||
- "Can we use BitwardenButton here instead of this custom button?"
|
||||
- "Should this color come from BitwardenTheme instead of being hardcoded?"
|
||||
- "How will this look on a small screen?"
|
||||
- "Is there a contentDescription for this icon?"
|
||||
|
||||
## Common Patterns
|
||||
|
||||
### Composable Structure
|
||||
|
||||
```kotlin
|
||||
// ✅ GOOD - Stateless, hoisted state
|
||||
@Composable
|
||||
fun FeatureScreen(
|
||||
state: FeatureState,
|
||||
onActionClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
// UI rendering only
|
||||
}
|
||||
|
||||
// ❌ BAD - Business state in composable
|
||||
@Composable
|
||||
fun FeatureScreen() {
|
||||
var userData by remember { mutableStateOf<User?>(null) } // Business state should be in ViewModel
|
||||
var isLoading by remember { mutableStateOf(false) } // App state should be in ViewModel
|
||||
// ...
|
||||
}
|
||||
|
||||
// ✅ OK - UI-local state in composable
|
||||
@Composable
|
||||
fun LoginForm(onSubmit: (String, String) -> Unit) {
|
||||
var username by remember { mutableStateOf("") } // UI-local input state is fine
|
||||
var password by remember { mutableStateOf("") }
|
||||
// Hoist only as high as needed
|
||||
}
|
||||
```
|
||||
|
||||
### Theme Usage
|
||||
|
||||
```kotlin
|
||||
// ✅ GOOD - Using theme
|
||||
Text(
|
||||
text = "Title",
|
||||
style = BitwardenTheme.typography.titleLarge,
|
||||
color = BitwardenTheme.colorScheme.primary
|
||||
)
|
||||
|
||||
// Design system uses 4.dp increments (4, 8, 12, 16, 24, 32, etc.)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
// ❌ BAD - Hardcoded
|
||||
Text(
|
||||
text = "Title",
|
||||
style = TextStyle(fontSize = 24.sp, fontWeight = FontWeight.Bold), // Should use theme
|
||||
color = Color(0xFF0000FF) // Should use theme color
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(17.dp)) // Non-standard spacing
|
||||
```
|
||||
|
||||
### Accessibility
|
||||
|
||||
```kotlin
|
||||
// ✅ GOOD - Interactive element with description
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_password),
|
||||
contentDescription = "Password visibility toggle",
|
||||
modifier = Modifier.clickable { onToggle() }
|
||||
)
|
||||
|
||||
// ✅ GOOD - Decorative icon with explicit null
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_check),
|
||||
contentDescription = null, // Decorative icon next to descriptive text
|
||||
tint = BitwardenTheme.colorScheme.success
|
||||
)
|
||||
|
||||
// ❌ BAD - Interactive element missing description
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_delete),
|
||||
contentDescription = null, // Interactive elements need descriptions
|
||||
modifier = Modifier.clickable { onDelete() }
|
||||
)
|
||||
```
|
||||
|
||||
## Prioritizing Findings
|
||||
|
||||
Use `reference/priority-framework.md` to classify findings as Critical/Important/Suggested/Optional.
|
||||
|
||||
## Output Format
|
||||
|
||||
Follow the format guidance from `SKILL.md` Step 5 (concise summary with critical issues only, detailed inline comments with `<details>` tags).
|
||||
|
||||
```markdown
|
||||
**Overall Assessment:** APPROVE / REQUEST CHANGES
|
||||
|
||||
**Critical Issues** (if any):
|
||||
- [One-line summary of each critical blocking issue with file:line reference]
|
||||
|
||||
See inline comments for all issue details.
|
||||
```
|
||||
|
||||
## Example Review
|
||||
|
||||
```markdown
|
||||
## Summary
|
||||
Updates login screen layout for improved visual hierarchy and touch targets
|
||||
|
||||
## Critical Issues
|
||||
None
|
||||
|
||||
## Suggested Improvements
|
||||
|
||||
**app/auth/LoginScreen.kt:67** - Can we use BitwardenTextField?
|
||||
This custom text field looks very similar to `ui/components/BitwardenTextField.kt:89`.
|
||||
Would using the existing component maintain consistency?
|
||||
|
||||
**app/auth/LoginScreen.kt:123** - Add contentDescription
|
||||
```kotlin
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_visibility),
|
||||
contentDescription = "Show password", // Add for accessibility
|
||||
modifier = Modifier.clickable { onToggleVisibility() }
|
||||
)
|
||||
```
|
||||
|
||||
**app/auth/LoginScreen.kt:145** - Use design system spacing
|
||||
```kotlin
|
||||
// Current
|
||||
Spacer(modifier = Modifier.height(17.dp))
|
||||
|
||||
// Design system uses 4.dp increments (4, 8, 12, 16, 24, 32, etc.)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
```
|
||||
```
|
||||
426
.claude/skills/reviewing-changes/examples/review-outputs.md
Normal file
426
.claude/skills/reviewing-changes/examples/review-outputs.md
Normal file
@@ -0,0 +1,426 @@
|
||||
# Review Output Examples
|
||||
|
||||
Well-structured code reviews demonstrating appropriate depth, tone, and formatting for different change types.
|
||||
|
||||
---
|
||||
|
||||
## Quick Format Reference
|
||||
|
||||
### Inline Comment Format (REQUIRED)
|
||||
|
||||
**MUST use `<details>` tags.** Only severity + description visible; all other content collapsed.
|
||||
|
||||
```
|
||||
[emoji] **[SEVERITY]**: [One-line issue description]
|
||||
|
||||
<details>
|
||||
<summary>Details and fix</summary>
|
||||
|
||||
[Code example or specific fix]
|
||||
|
||||
[Rationale explaining why]
|
||||
|
||||
Reference: [docs link if applicable]
|
||||
</details>
|
||||
```
|
||||
|
||||
**Severity Levels:**
|
||||
- ⚠️ **CRITICAL** - Blocking, must fix
|
||||
- 📋 **IMPORTANT** - Should fix
|
||||
- 💡 **SUGGESTED** - Nice to have
|
||||
- ❓ **QUESTION** - Seeking clarification
|
||||
|
||||
### Summary Comment Format
|
||||
|
||||
**Required format for ALL PRs:**
|
||||
```
|
||||
**Overall Assessment:** APPROVE / REQUEST CHANGES
|
||||
|
||||
**Critical Issues** (if any):
|
||||
- [issue with file:line]
|
||||
|
||||
See inline comments for details.
|
||||
```
|
||||
|
||||
All PRs use the same minimal format - no exceptions for size or complexity. Summary must be 5-10 lines maximum.
|
||||
|
||||
---
|
||||
|
||||
## Example 1: Clean PR (No Issues)
|
||||
|
||||
**Context**: Moving shared code to common module, complete migration, all patterns followed
|
||||
|
||||
**Review Comment:**
|
||||
```markdown
|
||||
**Overall Assessment:** APPROVE
|
||||
|
||||
Clean refactoring that moves ExitManager to :ui module, eliminating duplication between apps.
|
||||
```
|
||||
|
||||
**Why this works:**
|
||||
- Immediate approval visible (2-3 lines)
|
||||
- One sentence acknowledging the work
|
||||
- No unnecessary sections or elaborate praise
|
||||
- Author gets quick feedback and can proceed
|
||||
|
||||
---
|
||||
|
||||
## Example 2: Dependency Update with Breaking Changes
|
||||
|
||||
**Context**: Major version update requiring code migration
|
||||
|
||||
**Summary Comment:**
|
||||
```markdown
|
||||
**Overall Assessment:** REQUEST CHANGES
|
||||
|
||||
**Critical Issues:**
|
||||
- API migration required for Retrofit 3.0 breaking changes (network/api/BitwardenApiService.kt:34)
|
||||
|
||||
See inline comments for migration details.
|
||||
```
|
||||
|
||||
**Inline Comment 1** (on `network/api/BitwardenApiService.kt:34`):
|
||||
```markdown
|
||||
⚠️ **CRITICAL**: API migration required for Retrofit 3.0
|
||||
|
||||
<details>
|
||||
<summary>Details and fix</summary>
|
||||
|
||||
Retrofit 3.0 removes the `Call<T>` return type. All 12 API methods in this file need migration:
|
||||
|
||||
```kotlin
|
||||
// Current (deprecated in Retrofit 3.0)
|
||||
@GET("api/accounts/profile")
|
||||
fun getProfile(): Call<ProfileResponse>
|
||||
|
||||
// Must migrate to
|
||||
@GET("api/accounts/profile")
|
||||
suspend fun getProfile(): Response<ProfileResponse>
|
||||
```
|
||||
|
||||
Breaking API change affects:
|
||||
- 12 methods in BitwardenApiService
|
||||
- 8 methods in VaultApiService
|
||||
- All call sites using enqueue/execute
|
||||
- Test utilities
|
||||
|
||||
Consider creating separate PR for this migration given the scope.
|
||||
|
||||
Reference: [Retrofit 3.0 migration guide](https://square.github.io/retrofit/changelogs/changelog-3.x/)
|
||||
</details>
|
||||
```
|
||||
|
||||
**Key Features:**
|
||||
- Minimal summary (2-3 lines)
|
||||
- Full details in collapsed inline comment
|
||||
- Specific file:line references
|
||||
- Code examples in <details>
|
||||
- Migration guidance and scope assessment
|
||||
|
||||
---
|
||||
|
||||
## Example 3: Feature Addition with Critical Issues
|
||||
|
||||
**Context**: Implements PIN unlock for vault access
|
||||
|
||||
**Summary Comment:**
|
||||
```markdown
|
||||
**Overall Assessment:** REQUEST CHANGES
|
||||
|
||||
**Critical Issues:**
|
||||
- Exposes mutable state violating MVVM (UnlockViewModel.kt:78)
|
||||
- PIN stored without encryption - SECURITY ISSUE (UnlockRepository.kt:145)
|
||||
|
||||
See inline comments for all issues and suggestions.
|
||||
```
|
||||
|
||||
**Inline Comment 1** (on `app/vault/unlock/UnlockViewModel.kt:78`):
|
||||
```markdown
|
||||
⚠️ **CRITICAL**: Exposes mutable state
|
||||
|
||||
<details>
|
||||
<summary>Details and fix</summary>
|
||||
|
||||
Change `MutableStateFlow<State>` to `StateFlow<State>`:
|
||||
|
||||
```kotlin
|
||||
// Current (problematic)
|
||||
val unlockState: MutableStateFlow<UnlockState>
|
||||
|
||||
// Should be
|
||||
private val _unlockState = MutableStateFlow<UnlockState>()
|
||||
val unlockState: StateFlow<UnlockState> = _unlockState.asStateFlow()
|
||||
```
|
||||
|
||||
Exposing MutableStateFlow allows external mutation, violating MVVM unidirectional data flow.
|
||||
|
||||
Reference: docs/ARCHITECTURE.md#mvvm-pattern
|
||||
</details>
|
||||
```
|
||||
|
||||
**Inline Comment 2** (on `data/vault/UnlockRepository.kt:145`):
|
||||
```markdown
|
||||
⚠️ **CRITICAL**: PIN stored without encryption - SECURITY ISSUE
|
||||
|
||||
<details>
|
||||
<summary>Details and fix</summary>
|
||||
|
||||
Storing PIN in plaintext SharedPreferences exposes it to backup systems and rooted devices.
|
||||
|
||||
```kotlin
|
||||
// Current (CRITICAL SECURITY ISSUE)
|
||||
sharedPreferences.edit {
|
||||
putString(KEY_PIN, pin)
|
||||
}
|
||||
|
||||
// Must use Android Keystore encryption
|
||||
suspend fun storePin(pin: String): Result<Unit> = runCatching {
|
||||
val encrypted = keystoreManager.encrypt(pin.toByteArray())
|
||||
encryptedPrefs.putBytes(KEY_PIN, encrypted)
|
||||
}
|
||||
```
|
||||
|
||||
Use Android Keystore encryption or EncryptedSharedPreferences per security architecture.
|
||||
|
||||
Reference: docs/ARCHITECTURE.md#security
|
||||
</details>
|
||||
```
|
||||
|
||||
**Inline Comment 3** (on `app/vault/unlock/UnlockViewModel.kt:92`):
|
||||
```markdown
|
||||
📋 **IMPORTANT**: Missing error handling test
|
||||
|
||||
<details>
|
||||
<summary>Details and fix</summary>
|
||||
|
||||
Add test to prevent regression if error handling changes:
|
||||
|
||||
```kotlin
|
||||
@Test
|
||||
fun `when incorrect PIN entered then returns error state`() = runTest {
|
||||
val viewModel = UnlockViewModel(mockRepository)
|
||||
coEvery { mockRepository.validatePin("1234") }
|
||||
returns Result.failure(InvalidPinException())
|
||||
|
||||
viewModel.onPinEntered("1234")
|
||||
|
||||
assertEquals(UnlockState.Error("Invalid PIN"), viewModel.state.value)
|
||||
}
|
||||
```
|
||||
|
||||
Ensures error flow remains robust across refactorings.
|
||||
</details>
|
||||
```
|
||||
|
||||
**Inline Comment 4** (on `app/vault/unlock/UnlockViewModel.kt:105`):
|
||||
```markdown
|
||||
💡 **SUGGESTED**: Consider rate limiting for PIN attempts
|
||||
|
||||
<details>
|
||||
<summary>Details and fix</summary>
|
||||
|
||||
Currently allows unlimited attempts, which could enable brute force attacks.
|
||||
|
||||
```kotlin
|
||||
private var attemptCount = 0
|
||||
private var lockoutUntil: Instant? = null
|
||||
|
||||
fun onPinEntered(pin: String) {
|
||||
if (isLockedOut()) {
|
||||
_state.value = UnlockState.LockedOut(lockoutUntil!!)
|
||||
return
|
||||
}
|
||||
// ... validate PIN ...
|
||||
if (invalid) {
|
||||
attemptCount++
|
||||
if (attemptCount >= MAX_ATTEMPTS) {
|
||||
lockoutUntil = clock.millis() + 15.minutes
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Would add security layer against brute force. Consider discussing threat model with security team.
|
||||
</details>
|
||||
```
|
||||
|
||||
**Inline Comment 5** (on `app/vault/unlock/UnlockScreen.kt:134`):
|
||||
```markdown
|
||||
❓ **QUESTION**: Can we use BitwardenTextField?
|
||||
|
||||
<details>
|
||||
<summary>Details</summary>
|
||||
|
||||
This custom PIN input field looks similar to `ui/components/BitwardenTextField.kt:67`.
|
||||
|
||||
Would using the existing component maintain consistency and reduce custom UI code?
|
||||
</details>
|
||||
```
|
||||
|
||||
**Key Features:**
|
||||
- Minimal summary (3-4 lines) with critical issues only
|
||||
- Each issue gets separate inline comment with `<details>` tag
|
||||
- Multiple severity levels demonstrated (CRITICAL, IMPORTANT, SUGGESTED, QUESTION)
|
||||
- Mix of prescriptive fixes and collaborative questions
|
||||
- Code examples collapsed in <details>
|
||||
- No "Good Practices" or "Action Items" sections
|
||||
|
||||
---
|
||||
|
||||
## ❌ Anti-Patterns to Avoid
|
||||
|
||||
### Problem: Verbose Summary with Multiple Sections
|
||||
|
||||
**What NOT to do:**
|
||||
```markdown
|
||||
### Review Complete ✅
|
||||
|
||||
## Summary
|
||||
[Lengthy description of what the PR does]
|
||||
|
||||
### Strengths 👍
|
||||
1. **Excellent documentation** - KDoc comments are comprehensive
|
||||
2. **Proper fail-closed design** - Security defaults to rejection
|
||||
3. **Defense in depth** - Multiple validation layers
|
||||
[7 total items with elaboration]
|
||||
|
||||
### Critical Issues ⚠️
|
||||
- Missing test coverage for security-critical code (with full details)
|
||||
- [More issues with full explanations]
|
||||
|
||||
### Recommendations 🎨
|
||||
- [Multiple recommendations]
|
||||
|
||||
### Test Coverage Status 📊
|
||||
- [Analysis]
|
||||
|
||||
### Architecture Compliance ✅
|
||||
- [Analysis]
|
||||
|
||||
## Recommendation
|
||||
**Conditional approval** with follow-up...
|
||||
```
|
||||
|
||||
**Why this is wrong:**
|
||||
- 800+ tokens for a summary comment
|
||||
- Multiple sections (Strengths, Recommendations, Test Coverage, Architecture)
|
||||
- Elaborates on positive aspects ("Excellent documentation...")
|
||||
- Duplicates critical issues (summary has details + inline comments have same details)
|
||||
- Creates visual clutter in PR conversation
|
||||
|
||||
**Correct approach:**
|
||||
```markdown
|
||||
**Overall Assessment:** REQUEST CHANGES
|
||||
|
||||
**Critical Issues:**
|
||||
- Missing test coverage for security-critical code (PasswordManagerSignatureVerifierImpl.kt:47)
|
||||
|
||||
See inline comments for details.
|
||||
```
|
||||
|
||||
**Key differences:**
|
||||
- 3-5 lines vs 800+ tokens
|
||||
- Verdict + critical issues only
|
||||
- All details belong in inline comments
|
||||
- No positive commentary sections
|
||||
- Scales with PR complexity, not analysis thoroughness
|
||||
|
||||
### Problem: Praise-Only Inline Comments
|
||||
|
||||
**What NOT to do:**
|
||||
|
||||
Creating inline comment on `AuthenticatorBridgeManagerImpl.kt:73`:
|
||||
```markdown
|
||||
👍 **Excellent integration of signature verification**
|
||||
|
||||
The signature verification is properly integrated into the connection flow:
|
||||
- Checked during initialization (line 73)
|
||||
- Checked before binding (line 134)
|
||||
- Ensures only validated apps can connect
|
||||
|
||||
This is exactly the right approach for fail-safe security.
|
||||
```
|
||||
|
||||
**Why this is wrong:**
|
||||
- Entire comment is positive feedback with no actionable issue
|
||||
- Takes up space in PR conversation
|
||||
- Distracts from actual issues
|
||||
- Violates "focus on actionable feedback" principle
|
||||
|
||||
**Correct approach:**
|
||||
- Do not create this comment at all
|
||||
- Reserve inline comments exclusively for issues requiring attention
|
||||
|
||||
### Problem: Missing `<details>` Tags
|
||||
|
||||
**What NOT to do:**
|
||||
|
||||
```markdown
|
||||
⚠️ **CRITICAL**: Missing test coverage for security-critical code
|
||||
|
||||
The `@OmitFromCoverage` annotation excludes this entire class from test coverage.
|
||||
|
||||
**Problems:**
|
||||
1. No validation that certificate hashes match actual Bitwarden certificates
|
||||
2. No verification of fail-closed behavior on edge cases
|
||||
3. No tests for multiple signer rejection logic
|
||||
4. Certificate hash typos would go undetected until production
|
||||
|
||||
**Recommendation:**
|
||||
Replace `@OmitFromCoverage` with proper unit tests.
|
||||
|
||||
Example test structure:
|
||||
[long code block]
|
||||
|
||||
Security-critical code should have the highest test coverage, not be omitted.
|
||||
```
|
||||
|
||||
**Why this is wrong:**
|
||||
- All content visible immediately (code examples, problems list, rationale)
|
||||
- Creates visual clutter in PR conversation
|
||||
- Makes it hard to scan multiple issues quickly
|
||||
|
||||
**Correct approach:**
|
||||
```markdown
|
||||
⚠️ **CRITICAL**: Missing test coverage for security-critical code
|
||||
|
||||
<details>
|
||||
<summary>Details and fix</summary>
|
||||
|
||||
The `@OmitFromCoverage` annotation excludes this entire class from test coverage.
|
||||
|
||||
**Problems:**
|
||||
1. No validation that certificate hashes match actual Bitwarden certificates
|
||||
2. No verification of fail-closed behavior on edge cases
|
||||
3. No tests for multiple signer rejection logic
|
||||
4. Certificate hash typos would go undetected until production
|
||||
|
||||
**Recommendation:**
|
||||
Replace `@OmitFromCoverage` with proper unit tests.
|
||||
|
||||
Example test structure:
|
||||
[code block]
|
||||
|
||||
Security-critical code should have the highest test coverage, not be omitted.
|
||||
</details>
|
||||
```
|
||||
|
||||
**Key difference:** Only severity + one-line description visible. All details collapsed.
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
**Always use:**
|
||||
- Minimal summary (verdict + critical issues)
|
||||
- Separate inline comments with `<details>` tags
|
||||
- Hybrid emoji + text severity prefixes
|
||||
- Focus exclusively on actionable feedback
|
||||
|
||||
**Never use:**
|
||||
- Multiple summary sections (Strengths, Recommendations, etc.)
|
||||
- Praise-only inline comments
|
||||
- Duplication between summary and inline comments
|
||||
- Verbose analysis in summary (belongs in inline comments)
|
||||
|
||||
See `SKILL.md` for complete review guidelines.
|
||||
@@ -0,0 +1,296 @@
|
||||
# Architectural Patterns Quick Reference
|
||||
|
||||
Quick reference for Bitwarden Android architectural patterns during code reviews. For comprehensive details, read `docs/ARCHITECTURE.md` and `docs/STYLE_AND_BEST_PRACTICES.md`.
|
||||
|
||||
## MVVM + UDF Pattern
|
||||
|
||||
### ViewModel Structure
|
||||
|
||||
**✅ GOOD - Proper state encapsulation**:
|
||||
```kotlin
|
||||
@HiltViewModel
|
||||
class FeatureViewModel @Inject constructor(
|
||||
private val repository: FeatureRepository
|
||||
) : ViewModel() {
|
||||
// Private mutable state
|
||||
private val _state = MutableStateFlow<FeatureState>(FeatureState.Initial)
|
||||
|
||||
// Public immutable state
|
||||
val state: StateFlow<FeatureState> = _state.asStateFlow()
|
||||
|
||||
// Actions as functions, state updated via internal action
|
||||
fun onActionClicked() {
|
||||
viewModelScope.launch {
|
||||
val result = repository.performAction()
|
||||
sendAction(FeatureAction.Internal.ActionComplete(result))
|
||||
}
|
||||
}
|
||||
|
||||
// The ViewModel has a handler that processes the internal action
|
||||
private fun handleInternalAction(action: FeatureAction.Internal) {
|
||||
when (action) {
|
||||
is FeatureAction.Internal.ActionComplete -> {
|
||||
// The action handler evaluates the result and updates state
|
||||
action.result.fold(
|
||||
onSuccess = { _state.value = State.Success },
|
||||
onFailure = { _state.value = State.Error(it) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**❌ BAD - Common violations**:
|
||||
```kotlin
|
||||
class FeatureViewModel : ViewModel() {
|
||||
// ❌ Exposes mutable state
|
||||
val state: MutableStateFlow<FeatureState>
|
||||
|
||||
// ❌ Business logic in ViewModel
|
||||
fun onSubmit() {
|
||||
val encrypted = encryptionManager.encrypt(data) // Should be in Repository
|
||||
_state.value = FeatureState.Success
|
||||
}
|
||||
|
||||
// ❌ Direct Android framework dependency
|
||||
fun onCreate(context: Context) { // ViewModels shouldn't depend on Context
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Key Rules**:
|
||||
- Expose `StateFlow<T>`, never `MutableStateFlow<T>`
|
||||
- Delegate business logic to Repository/Manager
|
||||
- No direct Android framework dependencies (except ViewModel, SavedStateHandle)
|
||||
- Use `viewModelScope` for coroutines
|
||||
|
||||
Reference: `docs/ARCHITECTURE.md#mvvm-pattern`
|
||||
|
||||
---
|
||||
|
||||
### UI Layer (Compose)
|
||||
|
||||
**✅ GOOD - Stateless, observes only**:
|
||||
```kotlin
|
||||
@Composable
|
||||
fun FeatureScreen(
|
||||
state: FeatureState,
|
||||
onActionClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(modifier = modifier) {
|
||||
when (state) {
|
||||
is FeatureState.Loading -> LoadingIndicator()
|
||||
is FeatureState.Success -> SuccessContent(state.data)
|
||||
is FeatureState.Error -> ErrorMessage(state.error)
|
||||
}
|
||||
|
||||
BitwardenButton(
|
||||
text = "Action",
|
||||
onClick = onActionClick // Sends event to ViewModel
|
||||
)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**❌ BAD - Stateful, modifies state**:
|
||||
```kotlin
|
||||
@Composable
|
||||
fun FeatureScreen(viewModel: FeatureViewModel) {
|
||||
var localState by remember { mutableStateOf(...) } // ❌ State in UI
|
||||
|
||||
Button(onClick = {
|
||||
viewModel._state.value = FeatureState.Loading // ❌ Directly modifying ViewModel state
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
**Key Rules**:
|
||||
- Compose screens observe state, never modify
|
||||
- User actions passed as events/callbacks to ViewModel
|
||||
- No business logic in UI layer
|
||||
- Use existing components from `:ui` module
|
||||
|
||||
---
|
||||
|
||||
## Hilt Dependency Injection
|
||||
|
||||
### ViewModels
|
||||
|
||||
**✅ GOOD - Interface injection**:
|
||||
```kotlin
|
||||
@HiltViewModel
|
||||
class FeatureViewModel @Inject constructor(
|
||||
private val repository: FeatureRepository, // Interface, not implementation
|
||||
private val authManager: AuthManager,
|
||||
savedStateHandle: SavedStateHandle
|
||||
) : ViewModel()
|
||||
```
|
||||
|
||||
**❌ BAD - Common violations**:
|
||||
```kotlin
|
||||
// ❌ No @HiltViewModel annotation
|
||||
class FeatureViewModel @Inject constructor(...)
|
||||
|
||||
// ❌ Injecting implementation instead of interface
|
||||
class FeatureViewModel @Inject constructor(
|
||||
private val repository: FeatureRepositoryImpl // Should inject interface
|
||||
)
|
||||
|
||||
// ❌ Manual instantiation
|
||||
class FeatureViewModel : ViewModel() {
|
||||
private val repository = FeatureRepositoryImpl() // Should use @Inject
|
||||
}
|
||||
```
|
||||
|
||||
**Key Rules**:
|
||||
- Annotate with `@HiltViewModel`
|
||||
- Use `@Inject constructor`
|
||||
- Inject interfaces, not implementations
|
||||
- Use `SavedStateHandle` for process death survival
|
||||
|
||||
Reference: `docs/ARCHITECTURE.md#dependency-injection`
|
||||
|
||||
---
|
||||
|
||||
### Repositories and Managers
|
||||
|
||||
**✅ GOOD - Implementation with @Inject**:
|
||||
```kotlin
|
||||
interface FeatureRepository {
|
||||
suspend fun fetchData(): Result<Data>
|
||||
}
|
||||
|
||||
class FeatureRepositoryImpl @Inject constructor(
|
||||
private val apiService: FeatureApiService,
|
||||
private val database: FeatureDao
|
||||
) : FeatureRepository {
|
||||
override suspend fun fetchData(): Result<Data> = runCatching {
|
||||
apiService.getData()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Module provides interface**:
|
||||
```kotlin
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
abstract class DataModule {
|
||||
@Binds
|
||||
@Singleton
|
||||
abstract fun bindFeatureRepository(
|
||||
impl: FeatureRepositoryImpl
|
||||
): FeatureRepository
|
||||
}
|
||||
```
|
||||
|
||||
**Key Rules**:
|
||||
- Define interface for abstraction
|
||||
- Implementation uses `@Inject constructor`
|
||||
- Module binds implementation to interface
|
||||
- Appropriate scoping (`@Singleton`, `@ViewModelScoped`)
|
||||
|
||||
---
|
||||
|
||||
## Module Organization
|
||||
|
||||
```
|
||||
android/
|
||||
├── core/ # Shared utilities (cryptography, analytics, logging)
|
||||
├── data/ # Repositories, database, domain models
|
||||
├── network/ # API clients, network utilities
|
||||
├── ui/ # Reusable Compose components, theme
|
||||
├── app/ # Application, feature screens, ViewModels
|
||||
└── authenticator/ # Authenticator app (separate from password manager)
|
||||
```
|
||||
|
||||
**Correct Placement**:
|
||||
- UI screens and ViewModels → `:app`
|
||||
- Reusable Compose components → `:ui`
|
||||
- Data models and Repositories → `:data`
|
||||
- API services → `:network`
|
||||
- Cryptography, logging → `:core`
|
||||
|
||||
**Check for**:
|
||||
- No circular dependencies
|
||||
- Correct module placement
|
||||
- Proper visibility (internal vs public)
|
||||
|
||||
Reference: `docs/ARCHITECTURE.md#module-structure`
|
||||
|
||||
---
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Use Result Types, Not Exceptions
|
||||
|
||||
**✅ GOOD - Result-based**:
|
||||
```kotlin
|
||||
// Repository
|
||||
suspend fun fetchData(): Result<Data> = runCatching {
|
||||
apiService.getData()
|
||||
}
|
||||
|
||||
// ViewModel
|
||||
fun onFetch() {
|
||||
viewModelScope.launch {
|
||||
val result = repository.fetchData()
|
||||
sendAction(FeatureAction.Internal.FetchComplete(result))
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**❌ BAD - Exception-based in business logic**:
|
||||
```kotlin
|
||||
// ❌ Don't throw in business logic
|
||||
suspend fun fetchData(): Data {
|
||||
try {
|
||||
return apiService.getData()
|
||||
} catch (e: Exception) {
|
||||
throw FeatureException(e) // Don't throw in repositories
|
||||
}
|
||||
}
|
||||
|
||||
// ❌ Try-catch in ViewModel
|
||||
fun onFetch() {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val data = repository.fetchData()
|
||||
sendAction(FeatureAction.Internal.FetchComplete(data))
|
||||
} catch (e: Exception) {
|
||||
sendAction(FeatureAction.Internal.FetchComplete(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Key Rules**:
|
||||
- Use `Result<T>` return types in repositories
|
||||
- Use `runCatching { }` to wrap API calls
|
||||
- Handle results with `.fold()` in ViewModels
|
||||
- Don't throw exceptions in business logic
|
||||
|
||||
Reference: `docs/ARCHITECTURE.md#error-handling`
|
||||
|
||||
---
|
||||
|
||||
## Quick Checklist
|
||||
|
||||
### Architecture
|
||||
- [ ] ViewModels expose StateFlow, not MutableStateFlow?
|
||||
- [ ] Business logic in Repository, not ViewModel?
|
||||
- [ ] Using Hilt DI (@HiltViewModel, @Inject constructor)?
|
||||
- [ ] Injecting interfaces, not implementations?
|
||||
- [ ] Correct module placement?
|
||||
|
||||
### Error Handling
|
||||
- [ ] Using Result types, not exceptions in business logic?
|
||||
- [ ] Errors handled with .fold() in ViewModels?
|
||||
|
||||
---
|
||||
|
||||
For comprehensive details, always refer to:
|
||||
- `docs/ARCHITECTURE.md` - Full architecture patterns
|
||||
- `docs/STYLE_AND_BEST_PRACTICES.md` - Complete style guide
|
||||
274
.claude/skills/reviewing-changes/reference/priority-framework.md
Normal file
274
.claude/skills/reviewing-changes/reference/priority-framework.md
Normal file
@@ -0,0 +1,274 @@
|
||||
# Issue Priority Framework
|
||||
|
||||
Use this framework to classify findings during code review. Clear prioritization helps authors triage and address issues effectively.
|
||||
|
||||
## Critical (Blocker - Must Fix Before Merge)
|
||||
|
||||
These issues **must** be addressed before the PR can be merged. They pose immediate risks to security, stability, or architecture integrity.
|
||||
|
||||
### Security
|
||||
- Data leaks or plaintext sensitive data (passwords, keys, tokens)
|
||||
- Weak encryption or insecure key storage
|
||||
- Missing authentication or authorization checks
|
||||
- Input injection vulnerabilities (SQL, XSS, command injection)
|
||||
- Sensitive data in logs or error messages
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**data/vault/VaultRepository.kt:145** - CRITICAL: PIN stored without encryption
|
||||
PIN must be encrypted using Android Keystore, not stored in plaintext SharedPreferences.
|
||||
Reference: docs/ARCHITECTURE.md#security
|
||||
```
|
||||
|
||||
### Stability
|
||||
- Compilation errors or warnings
|
||||
- Null pointer exceptions in production paths
|
||||
- Resource leaks (file handles, network connections, memory)
|
||||
- Crashes or unhandled exceptions in critical paths
|
||||
- Thread safety violations
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**app/auth/BiometricRepository.kt:120** - CRITICAL: Missing null safety check
|
||||
biometricPrompt result can be null. Add explicit null check to prevent crash.
|
||||
```
|
||||
|
||||
### Architecture
|
||||
- Mutable state exposure in ViewModels (violates MVVM)
|
||||
- Exception-based error handling in business logic (should use Result)
|
||||
- Circular dependencies between modules
|
||||
- Violation of zero-knowledge principles
|
||||
- Direct dependency instantiation (should use DI)
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**app/login/LoginViewModel.kt:45** - CRITICAL: Exposes mutable state
|
||||
Change MutableStateFlow to StateFlow in public API to prevent external state mutation.
|
||||
This violates MVVM encapsulation pattern.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Important (Should Fix)
|
||||
|
||||
These issues should be addressed but don't block merge if there's a compelling reason. They improve code quality, maintainability, or robustness.
|
||||
|
||||
### Testing
|
||||
- Missing tests for critical paths (authentication, encryption, data sync)
|
||||
- Missing tests for new public APIs
|
||||
- Tests that don't verify actual behavior (test implementation, not behavior)
|
||||
- Missing test coverage for error scenarios
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**data/auth/BiometricRepository.kt** - IMPORTANT: Missing test for cancellation
|
||||
Add test for user cancellation scenario to prevent regression.
|
||||
```
|
||||
|
||||
### Architecture
|
||||
- Inconsistent patterns within PR (mixing error handling approaches)
|
||||
- Poor separation of concerns
|
||||
- Tight coupling between components
|
||||
- Not following established project patterns
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**app/vault/VaultViewModel.kt:89** - IMPORTANT: Business logic in ViewModel
|
||||
Encryption logic should be in Repository, not ViewModel.
|
||||
Reference: docs/ARCHITECTURE.md#mvvm-pattern
|
||||
```
|
||||
|
||||
### Documentation
|
||||
- Undocumented public APIs (missing KDoc)
|
||||
- Missing documentation for complex algorithms
|
||||
- Unclear naming or confusing interfaces
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**core/crypto/EncryptionManager.kt:34** - IMPORTANT: Missing KDoc
|
||||
Public encryption method should document parameters, return value, and exceptions.
|
||||
```
|
||||
|
||||
### Performance
|
||||
- Inefficient algorithms in hot paths (with evidence from profiling)
|
||||
- Blocking main thread with I/O operations
|
||||
- Memory inefficient data structures (with evidence)
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**app/vault/VaultListViewModel.kt:78** - IMPORTANT: N+1 query pattern
|
||||
Fetching items one-by-one in loop. Consider batch fetch to reduce database queries.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Suggested (Nice to Have)
|
||||
|
||||
These are improvement opportunities but not required. Consider the effort vs. benefit before requesting changes.
|
||||
|
||||
### Code Quality
|
||||
- Minor style inconsistencies (if not caught by linter)
|
||||
- Opportunities for DRY improvements
|
||||
- Better variable naming for clarity
|
||||
- Simplification opportunities
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**app/vault/VaultScreen.kt:145** - SUGGESTED: Consider extracting helper function
|
||||
This 20-line block appears in 3 places. Consider extracting to reduce duplication.
|
||||
```
|
||||
|
||||
### Testing
|
||||
- Additional test coverage for edge cases (beyond critical paths)
|
||||
- More comprehensive integration tests
|
||||
- Performance tests for non-critical paths
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**app/login/LoginViewModelTest.kt** - SUGGESTED: Add test for concurrent login attempts
|
||||
Not critical, but would increase confidence in edge case handling.
|
||||
```
|
||||
|
||||
### Refactoring
|
||||
- Extracting reusable patterns
|
||||
- Modernizing old patterns (if touching related code)
|
||||
- Improving testability
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**data/vault/VaultRepository.kt:200** - SUGGESTED: Consider extracting validation logic
|
||||
Could be extracted to separate validator class for reusability and testing.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Optional (Acknowledge But Don't Require)
|
||||
|
||||
Note good practices to reinforce positive patterns. Keep these **brief** - list only, no elaboration.
|
||||
|
||||
### Good Practices
|
||||
|
||||
**Format**: Simple bullet list, no explanation
|
||||
|
||||
```markdown
|
||||
## Good Practices
|
||||
- Proper Hilt DI usage throughout
|
||||
- Comprehensive unit test coverage
|
||||
- Clear separation of concerns
|
||||
- Well-documented public APIs
|
||||
```
|
||||
|
||||
**Don't do this** (too verbose):
|
||||
```markdown
|
||||
## Good Practices
|
||||
- Proper Hilt DI usage throughout: Great job using @Inject constructor and injecting interfaces! This follows our established patterns perfectly and makes the code very testable. Really excellent work here! 👍
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Classification Guidelines
|
||||
|
||||
### When Something is Between Categories
|
||||
|
||||
**If unsure between Critical and Important**:
|
||||
- Ask: "Could this cause production incidents, data loss, or security breaches?"
|
||||
- If yes → Critical
|
||||
- If no → Important
|
||||
|
||||
**If unsure between Important and Suggested**:
|
||||
- Ask: "Would I block merge over this?"
|
||||
- If yes → Important
|
||||
- If no → Suggested
|
||||
|
||||
**If unsure between Suggested and Optional**:
|
||||
- Ask: "Is this actionable feedback or just acknowledgment?"
|
||||
- If actionable → Suggested
|
||||
- If acknowledgment → Optional
|
||||
|
||||
### Context Matters
|
||||
|
||||
**Same issue, different contexts**:
|
||||
|
||||
```
|
||||
// Critical for production code
|
||||
Missing null safety check in auth flow → CRITICAL
|
||||
|
||||
// Suggested for internal test utility
|
||||
Missing null safety check in test helper → SUGGESTED
|
||||
```
|
||||
|
||||
**Same pattern, different risk levels**:
|
||||
|
||||
```
|
||||
// Critical for new feature
|
||||
Missing tests for new auth method → CRITICAL
|
||||
|
||||
// Important for bug fix
|
||||
Missing regression test → IMPORTANT
|
||||
|
||||
// Suggested for refactoring
|
||||
Missing tests for refactored helper → SUGGESTED
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Examples by Change Type
|
||||
|
||||
### Dependency Update
|
||||
- **Critical**: Known CVEs in old version not addressed
|
||||
- **Important**: Breaking changes that need migration
|
||||
- **Suggested**: Beta/alpha version stability concerns
|
||||
|
||||
### Bug Fix
|
||||
- **Critical**: Fix doesn't address root cause
|
||||
- **Important**: Missing regression test
|
||||
- **Suggested**: Similar bugs in related code
|
||||
|
||||
### Feature Addition
|
||||
- **Critical**: Security vulnerabilities, architecture violations
|
||||
- **Important**: Missing tests for critical paths
|
||||
- **Suggested**: Additional test coverage, minor refactoring
|
||||
|
||||
### UI Refinement
|
||||
- **Critical**: Missing accessibility for key actions
|
||||
- **Important**: Not using theme (hardcoded colors)
|
||||
- **Suggested**: Minor spacing/alignment improvements
|
||||
|
||||
### Refactoring
|
||||
- **Critical**: Changes behavior (should be behavior-preserving)
|
||||
- **Important**: Incomplete migration (mix of old/new patterns)
|
||||
- **Suggested**: Additional instances that could be refactored
|
||||
|
||||
### Infrastructure
|
||||
- **Critical**: Hardcoded secrets, no rollback plan
|
||||
- **Important**: Performance regression in build times
|
||||
- **Suggested**: Further optimization opportunities
|
||||
|
||||
---
|
||||
|
||||
## Special Cases
|
||||
|
||||
### Technical Debt
|
||||
- Acknowledge existing tech debt but don't require fixing in unrelated PR
|
||||
- Exception: If change makes tech debt worse, it's Important to address
|
||||
|
||||
### Scope Creep
|
||||
- Don't request changes outside PR scope
|
||||
- Can note as "Future consideration" but not required for this PR
|
||||
|
||||
### Linter-Catchable Issues
|
||||
- Don't flag issues that automated tools handle
|
||||
- Exception: If linter is misconfigured and missing real issues
|
||||
|
||||
### Personal Preferences
|
||||
- Don't flag unless grounded in project standards or architectural principles
|
||||
- Use "I-statements" if suggesting alternative approaches
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
**Critical**: Block merge, must fix (security, stability, architecture)
|
||||
**Important**: Should fix before merge (testing, quality, performance)
|
||||
**Suggested**: Nice to have, consider effort vs benefit
|
||||
**Optional**: Acknowledge good practices, keep brief
|
||||
161
.claude/skills/reviewing-changes/reference/review-psychology.md
Normal file
161
.claude/skills/reviewing-changes/reference/review-psychology.md
Normal file
@@ -0,0 +1,161 @@
|
||||
# Review Psychology: Constructive Feedback Phrasing
|
||||
|
||||
Effective code review feedback is clear, actionable, and constructive. This guide provides phrasing patterns for inline comments.
|
||||
|
||||
## Core Directives
|
||||
|
||||
- **Keep positive feedback minimal**: For clean PRs with no issues, use 2-3 line approval only. When acknowledging good practices in PRs with issues, use single bullet list with no elaboration. Never create elaborate sections praising correct implementations.
|
||||
- Ask questions for design decisions, be prescriptive for clear violations
|
||||
- Focus on code, not people ("This code..." not "You...")
|
||||
- Use I-statements for subjective feedback ("Hard for me to understand...")
|
||||
- Explain rationale with every recommendation
|
||||
- Avoid: "just", "simply", "obviously", "easy"
|
||||
|
||||
---
|
||||
|
||||
## Phrasing Templates
|
||||
|
||||
### Critical Issues (Prescriptive)
|
||||
|
||||
**Pattern**: State problem + Provide solution + Explain why
|
||||
|
||||
```
|
||||
**[file:line]** - CRITICAL: [Issue description]
|
||||
|
||||
[Specific fix with code example if applicable]
|
||||
|
||||
[Rationale explaining why this is critical]
|
||||
|
||||
Reference: [docs link if applicable]
|
||||
```
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**data/vault/VaultRepository.kt:145** - CRITICAL: PIN stored without encryption
|
||||
|
||||
PIN must be encrypted using Android Keystore, not stored in plaintext SharedPreferences.
|
||||
Plaintext storage exposes the PIN to backup systems and rooted devices.
|
||||
|
||||
Reference: docs/ARCHITECTURE.md#security
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Suggested Improvements (Exploratory)
|
||||
|
||||
**Pattern**: Observe + Suggest + Explain benefit
|
||||
|
||||
```
|
||||
**[file:line]** - Consider [alternative approach]
|
||||
|
||||
[Current observation]
|
||||
Can we [specific suggestion]?
|
||||
|
||||
[Benefit or rationale]
|
||||
```
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**app/login/LoginScreen.kt:89** - Consider using existing BitwardenButton
|
||||
|
||||
This custom button implementation looks similar to `ui/components/BitwardenButton.kt:45`.
|
||||
Can we use the existing component to maintain consistency across the app?
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Questions (Collaborative)
|
||||
|
||||
**Pattern**: Ask + Provide context (optional)
|
||||
|
||||
```
|
||||
**[file:line]** - [Question about intent or approach]?
|
||||
|
||||
[Optional context or observation]
|
||||
```
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**data/sync/SyncManager.kt:234** - How does this handle concurrent sync attempts?
|
||||
|
||||
It looks like multiple coroutines could call `startSync()` simultaneously.
|
||||
Is there a mechanism to prevent race conditions, or is that handled elsewhere?
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Test Suggestions
|
||||
|
||||
**Pattern**: Observe gap + Suggest specific test + Provide skeleton
|
||||
|
||||
```
|
||||
**[file:line]** - Consider adding test for [scenario]
|
||||
|
||||
[Rationale]
|
||||
|
||||
```kotlin
|
||||
@Test
|
||||
fun `test description`() = runTest {
|
||||
// Test skeleton
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
**Example**:
|
||||
```
|
||||
**data/auth/BiometricRepository.kt** - Consider adding test for cancellation scenario
|
||||
|
||||
This would prevent regression of the bug you just fixed:
|
||||
|
||||
```kotlin
|
||||
@Test
|
||||
fun `when biometric cancelled then returns cancelled state`() = runTest {
|
||||
coEvery { biometricPrompt.authenticate() } returns null
|
||||
|
||||
val result = repository.authenticate()
|
||||
|
||||
assertEquals(AuthResult.Cancelled, result)
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## When to Be Prescriptive vs Ask Questions
|
||||
|
||||
**Be Prescriptive** (Tell them what to do):
|
||||
- Security issues
|
||||
- Architecture pattern violations
|
||||
- Null safety problems
|
||||
- Compilation errors
|
||||
- Documented project standards
|
||||
|
||||
**Ask Questions** (Seek explanation):
|
||||
- Design decisions with multiple valid approaches
|
||||
- Performance trade-offs without data
|
||||
- Unclear intent or reasoning
|
||||
- Scope decisions (this PR vs future work)
|
||||
- Patterns not documented in project guidelines
|
||||
|
||||
---
|
||||
|
||||
## Special Cases
|
||||
|
||||
**Nitpicks** - For truly minor suggestions, use "Nit:" prefix:
|
||||
```
|
||||
**Nit**: Extra blank line at line 145
|
||||
```
|
||||
|
||||
**Uncertainty** - If unsure, acknowledge it:
|
||||
```
|
||||
I'm not certain, but this might be called frequently.
|
||||
Has this been profiled?
|
||||
```
|
||||
|
||||
**Positive Feedback** - Brief list only, no elaboration:
|
||||
```
|
||||
## Good Practices
|
||||
- Proper Hilt DI usage throughout
|
||||
- Comprehensive unit test coverage
|
||||
- Clear separation of concerns
|
||||
```
|
||||
@@ -0,0 +1,90 @@
|
||||
# Security Patterns Quick Reference
|
||||
|
||||
Quick reference for Bitwarden Android security patterns during code reviews. For comprehensive details, read `docs/ARCHITECTURE.md#security`.
|
||||
|
||||
## Encryption and Key Storage
|
||||
|
||||
**✅ GOOD - Android Keystore**:
|
||||
```kotlin
|
||||
// Sensitive data encrypted with Keystore
|
||||
class SecureStorage @Inject constructor(
|
||||
private val keystoreManager: KeystoreManager
|
||||
) {
|
||||
suspend fun storePin(pin: String): Result<Unit> = runCatching {
|
||||
val encrypted = keystoreManager.encrypt(pin.toByteArray())
|
||||
securePreferences.putBytes(KEY_PIN, encrypted)
|
||||
}
|
||||
}
|
||||
|
||||
// Or use EncryptedSharedPreferences
|
||||
val encryptedPrefs = EncryptedSharedPreferences.create(
|
||||
context,
|
||||
"secure_prefs",
|
||||
masterKey,
|
||||
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
||||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
|
||||
)
|
||||
```
|
||||
|
||||
**❌ BAD - Plaintext or weak encryption**:
|
||||
```kotlin
|
||||
// ❌ CRITICAL - Plaintext storage
|
||||
sharedPreferences.edit {
|
||||
putString("pin", userPin) // Never store sensitive data in plaintext
|
||||
}
|
||||
|
||||
// ❌ CRITICAL - Weak encryption
|
||||
val cipher = Cipher.getInstance("DES") // Use AES-256-GCM
|
||||
|
||||
// ❌ CRITICAL - Hardcoded keys
|
||||
val key = "my_secret_key_123" // Use Android Keystore
|
||||
```
|
||||
|
||||
**Key Rules**:
|
||||
- Use Android Keystore for encryption keys
|
||||
- Use EncryptedSharedPreferences for simple key-value storage
|
||||
- Use AES-256-GCM for encryption
|
||||
- Never store sensitive data in plaintext
|
||||
- Never hardcode encryption keys
|
||||
|
||||
Reference: `docs/ARCHITECTURE.md#security`
|
||||
|
||||
---
|
||||
|
||||
## Logging Sensitive Data
|
||||
|
||||
**✅ GOOD - No sensitive data**:
|
||||
```kotlin
|
||||
Log.d(TAG, "Authentication attempt for user")
|
||||
Log.d(TAG, "Vault sync completed with ${items.size} items")
|
||||
```
|
||||
|
||||
**❌ BAD - Logs sensitive data**:
|
||||
```kotlin
|
||||
// ❌ CRITICAL
|
||||
Log.d(TAG, "Password: $password")
|
||||
Log.d(TAG, "Auth token: $token")
|
||||
Log.d(TAG, "PIN: $pin")
|
||||
Log.d(TAG, "Encryption key: ${key.encoded}")
|
||||
```
|
||||
|
||||
**Key Rules**:
|
||||
- Never log passwords, PINs, tokens, keys
|
||||
- Never log encryption keys or sensitive data
|
||||
- Be careful with error messages (don't include sensitive context)
|
||||
|
||||
---
|
||||
|
||||
## Quick Checklist
|
||||
|
||||
### Security
|
||||
- [ ] Sensitive data encrypted with Keystore?
|
||||
- [ ] No plaintext passwords/keys?
|
||||
- [ ] No sensitive data in logs?
|
||||
- [ ] Using AES-256-GCM for encryption?
|
||||
- [ ] No hardcoded encryption keys?
|
||||
|
||||
---
|
||||
|
||||
For comprehensive security details, always refer to:
|
||||
- `docs/ARCHITECTURE.md#security` - Complete security architecture and zero-knowledge principles
|
||||
127
.claude/skills/reviewing-changes/reference/testing-patterns.md
Normal file
127
.claude/skills/reviewing-changes/reference/testing-patterns.md
Normal file
@@ -0,0 +1,127 @@
|
||||
# Testing Patterns Quick Reference
|
||||
|
||||
Quick reference for Bitwarden Android testing patterns during code reviews. For comprehensive details, read `docs/ARCHITECTURE.md` and `docs/STYLE_AND_BEST_PRACTICES.md`.
|
||||
|
||||
## ViewModel Tests
|
||||
|
||||
**✅ GOOD - Tests behavior**:
|
||||
```kotlin
|
||||
@Test
|
||||
fun `when login succeeds then state updates to success`() = runTest {
|
||||
// Arrange
|
||||
val viewModel = LoginViewModel(mockRepository)
|
||||
coEvery { mockRepository.login(any(), any()) } returns Result.success(User())
|
||||
|
||||
// Act
|
||||
viewModel.onLoginClicked("user@example.com", "password")
|
||||
|
||||
// Assert
|
||||
viewModel.state.test {
|
||||
assertEquals(LoginState.Loading, awaitItem())
|
||||
assertEquals(LoginState.Success, awaitItem())
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**❌ BAD - Tests implementation**:
|
||||
```kotlin
|
||||
@Test
|
||||
fun `repository is called with correct parameters`() {
|
||||
// ❌ This tests implementation details, not behavior
|
||||
viewModel.onLoginClicked("user", "pass")
|
||||
coVerify { mockRepository.login("user", "pass") }
|
||||
}
|
||||
```
|
||||
|
||||
**Key Rules**:
|
||||
- Test behavior, not implementation
|
||||
- Use `runTest` for coroutine tests
|
||||
- Use Turbine for Flow testing
|
||||
- Use MockK for mocking
|
||||
|
||||
---
|
||||
|
||||
## Repository Tests
|
||||
|
||||
**✅ GOOD - Tests data transformations**:
|
||||
```kotlin
|
||||
@Test
|
||||
fun `fetchItems maps API response to domain model`() = runTest {
|
||||
// Arrange
|
||||
val apiResponse = listOf(ApiItem(id = "1", name = "Test"))
|
||||
coEvery { apiService.getItems() } returns apiResponse
|
||||
|
||||
// Act
|
||||
val result = repository.fetchItems()
|
||||
|
||||
// Assert
|
||||
assertTrue(result.isSuccess)
|
||||
assertEquals(
|
||||
listOf(DomainItem(id = "1", name = "Test")),
|
||||
result.getOrThrow()
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
**Key Rules**:
|
||||
- Test data transformations
|
||||
- Test error handling (network failures, API errors)
|
||||
- Test caching behavior if applicable
|
||||
- Mock API services and databases
|
||||
|
||||
Reference: Project uses JUnit 5, MockK, Turbine, kotlinx-coroutines-test
|
||||
|
||||
---
|
||||
|
||||
## Null Safety
|
||||
|
||||
**✅ GOOD - Safe handling**:
|
||||
```kotlin
|
||||
// Safe call with elvis operator
|
||||
val result = apiService.getData() ?: return State.Error("No data")
|
||||
|
||||
// Let with safe call
|
||||
intent?.getStringExtra("key")?.let { value ->
|
||||
processValue(value)
|
||||
}
|
||||
|
||||
// Require with message
|
||||
val data = requireNotNull(response.data) { "Response data must not be null" }
|
||||
```
|
||||
|
||||
**❌ BAD - Unsafe assertions**:
|
||||
```kotlin
|
||||
// ❌ Unsafe - can crash
|
||||
val result = apiService.getData()!!
|
||||
|
||||
// ❌ Platform type unchecked
|
||||
val intent: Intent = getIntent() // Could be null from Java
|
||||
val value = intent.getStringExtra("key") // Potential NPE
|
||||
```
|
||||
|
||||
**Key Rules**:
|
||||
- Avoid `!!` unless safety is guaranteed (rare)
|
||||
- Handle platform types with explicit nullability
|
||||
- Use safe calls (`?.`), elvis operator (`?:`), or explicit checks
|
||||
- Use `requireNotNull` with descriptive message if crash is acceptable
|
||||
|
||||
---
|
||||
|
||||
## Quick Checklist
|
||||
|
||||
### Testing
|
||||
- [ ] ViewModels have unit tests?
|
||||
- [ ] Tests verify behavior, not implementation?
|
||||
- [ ] Edge cases covered?
|
||||
- [ ] Error scenarios tested?
|
||||
|
||||
### Code Quality
|
||||
- [ ] Null safety handled properly (no `!!` without guarantee)?
|
||||
- [ ] Public APIs have KDoc?
|
||||
- [ ] Following naming conventions?
|
||||
|
||||
---
|
||||
|
||||
For comprehensive details, always refer to:
|
||||
- `docs/ARCHITECTURE.md` - Full architecture patterns
|
||||
- `docs/STYLE_AND_BEST_PRACTICES.md` - Complete style guide
|
||||
85
.claude/skills/reviewing-changes/reference/ui-patterns.md
Normal file
85
.claude/skills/reviewing-changes/reference/ui-patterns.md
Normal file
@@ -0,0 +1,85 @@
|
||||
# Compose UI Patterns Quick Reference
|
||||
|
||||
Quick reference for Bitwarden Android Compose UI patterns during code reviews. For comprehensive details, read `docs/ARCHITECTURE.md` and `docs/STYLE_AND_BEST_PRACTICES.md`.
|
||||
|
||||
## Component Reuse
|
||||
|
||||
**✅ GOOD - Uses existing components**:
|
||||
```kotlin
|
||||
BitwardenButton(
|
||||
text = "Submit",
|
||||
onClick = onSubmit
|
||||
)
|
||||
|
||||
BitwardenTextField(
|
||||
value = text,
|
||||
onValueChange = onTextChange,
|
||||
label = "Email"
|
||||
)
|
||||
```
|
||||
|
||||
**❌ BAD - Duplicates existing components**:
|
||||
```kotlin
|
||||
// ❌ Recreating BitwardenButton
|
||||
Button(
|
||||
onClick = onSubmit,
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = BitwardenTheme.colorScheme.primary
|
||||
)
|
||||
) {
|
||||
Text("Submit")
|
||||
}
|
||||
```
|
||||
|
||||
**Key Rules**:
|
||||
- Check `:ui` module for existing components before creating custom ones
|
||||
- Use BitwardenButton, BitwardenTextField, etc. for consistency
|
||||
- Place new reusable components in `:ui` module
|
||||
|
||||
---
|
||||
|
||||
## Theme Usage
|
||||
|
||||
**✅ GOOD - Uses theme**:
|
||||
```kotlin
|
||||
Text(
|
||||
text = "Title",
|
||||
style = BitwardenTheme.typography.titleLarge,
|
||||
color = BitwardenTheme.colorScheme.primary
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp)) // Standard spacing
|
||||
```
|
||||
|
||||
**❌ BAD - Hardcoded values**:
|
||||
```kotlin
|
||||
Text(
|
||||
text = "Title",
|
||||
style = TextStyle(fontSize = 24.sp, fontWeight = FontWeight.Bold), // Use theme
|
||||
color = Color(0xFF0066FF) // Use theme color
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(17.dp)) // Non-standard spacing
|
||||
```
|
||||
|
||||
**Key Rules**:
|
||||
- Use `BitwardenTheme.colorScheme` for colors
|
||||
- Use `BitwardenTheme.typography` for text styles
|
||||
- Use standard spacing (4.dp, 8.dp, 16.dp, 24.dp)
|
||||
|
||||
---
|
||||
|
||||
## Quick Checklist
|
||||
|
||||
### UI Patterns
|
||||
- [ ] Using existing Bitwarden components from `:ui` module?
|
||||
- [ ] Using BitwardenTheme for colors and typography?
|
||||
- [ ] Using standard spacing values (4, 8, 16, 24 dp)?
|
||||
- [ ] No hardcoded colors or text styles?
|
||||
- [ ] UI is stateless (observes state, doesn't modify)?
|
||||
|
||||
---
|
||||
|
||||
For comprehensive details, always refer to:
|
||||
- `docs/ARCHITECTURE.md` - Full architecture patterns
|
||||
- `docs/STYLE_AND_BEST_PRACTICES.md` - Complete style guide
|
||||
5
.github/CODEOWNERS
vendored
5
.github/CODEOWNERS
vendored
@@ -10,6 +10,11 @@
|
||||
# Actions and workflow changes.
|
||||
.github/ @bitwarden/dept-development-mobile
|
||||
|
||||
# Claude related files
|
||||
.claude/ @bitwarden/team-ai-sme
|
||||
.github/workflows/respond.yml @bitwarden/team-ai-sme
|
||||
.github/workflows/review-code.yml @bitwarden/team-ai-sme
|
||||
|
||||
# Auth
|
||||
# app/src/main/java/com/x8bit/bitwarden/data/auth @bitwarden/team-auth-dev
|
||||
# app/src/main/java/com/x8bit/bitwarden/ui/auth @bitwarden/team-auth-dev
|
||||
|
||||
16
.github/actions/log-inputs/action.yml
vendored
16
.github/actions/log-inputs/action.yml
vendored
@@ -11,10 +11,14 @@ runs:
|
||||
steps:
|
||||
- name: Log inputs to job summary
|
||||
shell: bash
|
||||
env:
|
||||
INPUTS: ${{ inputs.inputs }}
|
||||
run: |
|
||||
echo "<details><summary>Job Inputs</summary>" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo '```json' >> $GITHUB_STEP_SUMMARY
|
||||
echo '${{ inputs.inputs }}' >> $GITHUB_STEP_SUMMARY
|
||||
echo '```' >> $GITHUB_STEP_SUMMARY
|
||||
echo "</details>" >> $GITHUB_STEP_SUMMARY
|
||||
{
|
||||
echo "<details><summary>Job Inputs</summary>"
|
||||
echo ""
|
||||
echo '```json'
|
||||
echo "$INPUTS"
|
||||
echo '```'
|
||||
echo "</details>"
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
49
.github/label-pr.json
vendored
Normal file
49
.github/label-pr.json
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"catch_all_label": "t:misc",
|
||||
"title_patterns": {
|
||||
"t:new-feature": ["feat", "feature"],
|
||||
"t:enhancement": ["enhancement", "enh", "impr"],
|
||||
"t:bug": ["fix", "bug", "bugfix"],
|
||||
"t:tech-debt": ["refactor", "chore", "cleanup", "revert", "debt", "test", "perf"],
|
||||
"t:docs": ["docs"],
|
||||
"t:ci": ["ci", "build", "chore(ci)"],
|
||||
"t:deps": ["deps"],
|
||||
"t:breaking-change": ["breaking", "breaking-change"],
|
||||
"t:misc": ["misc"]
|
||||
},
|
||||
"path_patterns": {
|
||||
"app:shared": [
|
||||
"annotation/",
|
||||
"core/",
|
||||
"data/",
|
||||
"network/",
|
||||
"ui/",
|
||||
"authenticatorbridge/",
|
||||
"gradle/"
|
||||
],
|
||||
"app:password-manager": [
|
||||
"app/",
|
||||
"cxf/"
|
||||
],
|
||||
"app:authenticator": [
|
||||
"authenticator/"
|
||||
],
|
||||
"t:ci": [
|
||||
".github/",
|
||||
"scripts/",
|
||||
"fastlane/",
|
||||
".gradle/",
|
||||
".claude/",
|
||||
"detekt-config.yml"
|
||||
],
|
||||
"t:docs": [
|
||||
"docs/"
|
||||
],
|
||||
"t:deps": [
|
||||
"gradle/"
|
||||
],
|
||||
"t:misc": [
|
||||
"keystore/"
|
||||
]
|
||||
}
|
||||
}
|
||||
3
.github/renovate.json
vendored
3
.github/renovate.json
vendored
@@ -29,7 +29,8 @@
|
||||
"gradle"
|
||||
],
|
||||
"excludePackageNames": [
|
||||
"com.github.bumptech.glide:compose"
|
||||
"com.github.bumptech.glide:compose",
|
||||
"com.bitwarden:sdk-android"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
238
.github/scripts/label-pr.py
vendored
Normal file
238
.github/scripts/label-pr.py
vendored
Normal file
@@ -0,0 +1,238 @@
|
||||
#!/usr/bin/env python3
|
||||
# Requires Python 3.9+
|
||||
"""
|
||||
Label pull requests based on changed file paths and PR title patterns (conventional commit format).
|
||||
|
||||
Usage:
|
||||
python label-pr.py <pr-number> [-a|--add|-r|--replace] [-d|--dry-run] [-c|--config CONFIG]
|
||||
|
||||
Arguments:
|
||||
pr-number: The pull request number
|
||||
-a, --add: Add labels without removing existing ones (default)
|
||||
-r, --replace: Replace all existing labels
|
||||
-d, --dry-run: Run without actually applying labels
|
||||
-c, --config: Path to JSON config file (default: .github/label-pr.json)
|
||||
|
||||
Examples:
|
||||
python label-pr.py 1234
|
||||
python label-pr.py 1234 -a
|
||||
python label-pr.py 1234 --replace
|
||||
python label-pr.py 1234 -r -d
|
||||
python label-pr.py 1234 --config custom-config.json
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
DEFAULT_MODE = "add"
|
||||
DEFAULT_CONFIG_PATH = ".github/label-pr.json"
|
||||
|
||||
def load_config_json(config_file: str) -> dict:
|
||||
"""Load configuration from JSON file."""
|
||||
if not os.path.exists(config_file):
|
||||
print(f"❌ Config file not found: {config_file}")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
with open(config_file, 'r') as f:
|
||||
config = json.load(f)
|
||||
print(f"✅ Loaded config from: {config_file}")
|
||||
|
||||
valid_config = True
|
||||
if not config.get("catch_all_label"):
|
||||
print("❌ Missing 'catch_all_label' in config file")
|
||||
valid_config = False
|
||||
if not config.get("title_patterns"):
|
||||
print("❌ Missing 'title_patterns' in config file")
|
||||
valid_config = False
|
||||
if not config.get("path_patterns"):
|
||||
print("❌ Missing 'path_patterns' in config file")
|
||||
valid_config = False
|
||||
|
||||
if not valid_config:
|
||||
print("::error::Invalid label-pr.json config file, exiting...")
|
||||
sys.exit(1)
|
||||
|
||||
return config
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"❌ JSON deserialization error in label-pr.json config: {e}")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"❌ Unexpected error loading label-pr.json config: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
def gh_get_changed_files(pr_number: str) -> list[str]:
|
||||
"""Get list of changed files in a pull request."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["gh", "pr", "diff", pr_number, "--name-only"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
changed_files = result.stdout.strip().split("\n")
|
||||
return list(filter(None, changed_files))
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"::error::Error getting changed files: {e}")
|
||||
return []
|
||||
|
||||
def gh_get_pr_title(pr_number: str) -> str:
|
||||
"""Get the title of a pull request."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["gh", "pr", "view", pr_number, "--json", "title", "--jq", ".title"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
return result.stdout.strip()
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"::error::Error getting PR title: {e}")
|
||||
return ""
|
||||
|
||||
def gh_add_labels(pr_number: str, labels: list[str]) -> None:
|
||||
"""Add labels to a pull request (doesn't remove existing labels)."""
|
||||
gh_labels = ','.join(labels)
|
||||
subprocess.run(
|
||||
["gh", "pr", "edit", pr_number, "--add-label", gh_labels],
|
||||
check=True
|
||||
)
|
||||
|
||||
def gh_replace_labels(pr_number: str, labels: list[str]) -> None:
|
||||
"""Replace all labels on a pull request with the specified labels."""
|
||||
payload = json.dumps({"labels": labels})
|
||||
subprocess.run(
|
||||
["gh", "api", "repos/{owner}/{repo}/issues/" + pr_number, "-X", "PATCH", "--silent", "--input", "-"],
|
||||
input=payload,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
|
||||
def label_filepaths(changed_files: list[str], path_patterns: dict) -> list[str]:
|
||||
"""Check changed files against path patterns and return labels to apply."""
|
||||
if not changed_files:
|
||||
return []
|
||||
|
||||
labels_to_apply = set() # Use set to avoid duplicates
|
||||
|
||||
for label, patterns in path_patterns.items():
|
||||
for file in changed_files:
|
||||
if any(file.startswith(pattern) for pattern in patterns):
|
||||
print(f"👀 File '{file}' matches pattern for label '{label}'")
|
||||
labels_to_apply.add(label)
|
||||
break
|
||||
|
||||
if "app:shared" in labels_to_apply:
|
||||
labels_to_apply.add("app:password-manager")
|
||||
labels_to_apply.add("app:authenticator")
|
||||
labels_to_apply.remove("app:shared")
|
||||
|
||||
if not labels_to_apply:
|
||||
print("::warning::No matching file paths found, no labels applied.")
|
||||
|
||||
return list(labels_to_apply)
|
||||
|
||||
def label_title(pr_title: str, title_patterns: dict) -> list[str]:
|
||||
"""Check PR title against patterns and return labels to apply."""
|
||||
if not pr_title:
|
||||
return []
|
||||
|
||||
labels_to_apply = set()
|
||||
title_lower = pr_title.lower()
|
||||
for label, patterns in title_patterns.items():
|
||||
for pattern in patterns:
|
||||
# Check for pattern with : or ( suffix (conventional commits format)
|
||||
if f"{pattern}:" in title_lower or f"{pattern}(" in title_lower:
|
||||
print(f"📝 Title matches pattern '{pattern}' for label '{label}'")
|
||||
labels_to_apply.add(label)
|
||||
break
|
||||
|
||||
if not labels_to_apply:
|
||||
print("::warning::No matching title patterns found, no labels applied.")
|
||||
|
||||
return list(labels_to_apply)
|
||||
|
||||
def parse_args():
|
||||
"""Parse command line arguments."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Label pull requests based on changed file paths and PR title patterns."
|
||||
)
|
||||
parser.add_argument(
|
||||
"pr_number",
|
||||
help="The pull request number"
|
||||
)
|
||||
|
||||
mode_group = parser.add_mutually_exclusive_group()
|
||||
mode_group.add_argument(
|
||||
"-a", "--add",
|
||||
action="store_true",
|
||||
help="Add labels without removing existing ones (default)"
|
||||
)
|
||||
mode_group.add_argument(
|
||||
"-r", "--replace",
|
||||
action="store_true",
|
||||
help="Replace all existing labels"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-d", "--dry-run",
|
||||
action="store_true",
|
||||
help="Run without actually applying labels"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-c", "--config",
|
||||
default=DEFAULT_CONFIG_PATH,
|
||||
help=f"Path to JSON config file (default: {DEFAULT_CONFIG_PATH})"
|
||||
)
|
||||
args, unknown = parser.parse_known_args() # required to handle --dry-run passed as an empty string ("") by the workflow
|
||||
return args
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
config = load_config_json(args.config)
|
||||
CATCH_ALL_LABEL = config["catch_all_label"]
|
||||
LABEL_TITLE_PATTERNS = config["title_patterns"]
|
||||
LABEL_PATH_PATTERNS = config["path_patterns"]
|
||||
|
||||
pr_number = args.pr_number
|
||||
mode = "replace" if args.replace else "add"
|
||||
|
||||
if args.dry_run:
|
||||
print("🔍 DRY RUN MODE - Labels will not be applied")
|
||||
print(f"📌 Labeling mode: {mode}")
|
||||
print(f"🔍 Checking PR #{pr_number}...")
|
||||
|
||||
pr_title = gh_get_pr_title(pr_number)
|
||||
print(f"📋 PR Title: {pr_title}\n")
|
||||
|
||||
changed_files = gh_get_changed_files(pr_number)
|
||||
print("👀 Changed files:\n" + "\n".join(changed_files) + "\n")
|
||||
|
||||
filepath_labels = label_filepaths(changed_files, LABEL_PATH_PATTERNS)
|
||||
title_labels = label_title(pr_title, LABEL_TITLE_PATTERNS)
|
||||
all_labels = set(filepath_labels + title_labels)
|
||||
|
||||
if not any(label.startswith("t:") for label in all_labels):
|
||||
all_labels.add(CATCH_ALL_LABEL)
|
||||
|
||||
if all_labels:
|
||||
labels_str = ', '.join(sorted(all_labels))
|
||||
if mode == "add":
|
||||
print(f"🏷️ Adding labels: {labels_str}")
|
||||
if not args.dry_run:
|
||||
gh_add_labels(pr_number, list(all_labels))
|
||||
else:
|
||||
print(f"🏷️ Replacing labels with: {labels_str}")
|
||||
if not args.dry_run:
|
||||
gh_replace_labels(pr_number, list(all_labels))
|
||||
else:
|
||||
print("ℹ️ No matching patterns found, no labels applied.")
|
||||
|
||||
print("✅ Done")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
173
.github/workflows/_version.yml
vendored
Normal file
173
.github/workflows/_version.yml
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
name: Calculate Version Name and Number
|
||||
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
app_codename:
|
||||
description: "App Name - e.g. 'bwpm' or 'bwa'"
|
||||
base_version_number:
|
||||
description: "Base Version Number - Will be added to the calculated version number"
|
||||
type: number
|
||||
default: 0
|
||||
version_name:
|
||||
description: "Version Name Override - e.g. '2024.8.1'"
|
||||
version_number:
|
||||
description: "Version Number Override - e.g. '1021'"
|
||||
patch_version:
|
||||
description: "Patch Version Override - e.g. '999'"
|
||||
distinct_id:
|
||||
description: "Unique ID for this dispatch, used by dispatch-and-download.yml"
|
||||
skip_checkout:
|
||||
description: "Skip checking out the repository"
|
||||
type: boolean
|
||||
workflow_call:
|
||||
inputs:
|
||||
app_codename:
|
||||
description: "App Name - e.g. 'bwpm' or 'bwa'"
|
||||
type: string
|
||||
base_version_number:
|
||||
description: "Base Version Number - Will be added to the calculated version number"
|
||||
type: number
|
||||
default: 0
|
||||
version_name:
|
||||
description: "Version Name Override - e.g. '2024.8.1'"
|
||||
type: string
|
||||
version_number:
|
||||
description: "Version Number Override - e.g. '1021'"
|
||||
type: string
|
||||
patch_version:
|
||||
description: "Patch Version Override - e.g. '999'"
|
||||
type: string
|
||||
distinct_id:
|
||||
description: "Unique ID for this dispatch, used by dispatch-and-download.yml"
|
||||
type: string
|
||||
skip_checkout:
|
||||
description: "Skip checking out the repository"
|
||||
type: boolean
|
||||
outputs:
|
||||
version_name:
|
||||
description: "Version Name"
|
||||
value: ${{ jobs.calculate-version.outputs.version_name }}
|
||||
version_number:
|
||||
description: "Version Number"
|
||||
value: ${{ jobs.calculate-version.outputs.version_number }}
|
||||
|
||||
env:
|
||||
APP_CODENAME: ${{ inputs.app_codename }}
|
||||
BASE_VERSION_NUMBER: ${{ inputs.base_version_number || 0 }}
|
||||
|
||||
jobs:
|
||||
calculate-version:
|
||||
name: Calculate Version Name and Number
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
contents: read
|
||||
outputs:
|
||||
version_name: ${{ steps.calc-version-name.outputs.version_name }}
|
||||
version_number: ${{ steps.calc-version-number.outputs.version_number }}
|
||||
steps:
|
||||
- name: Log inputs to job summary
|
||||
uses: bitwarden/android/.github/actions/log-inputs@main
|
||||
with:
|
||||
inputs: "${{ toJson(inputs) }}"
|
||||
|
||||
- name: Echo distinct ID ${{ github.event.inputs.distinct_id }}
|
||||
env:
|
||||
_DISTINCT_ID: ${{ inputs.distinct_id }}
|
||||
run: echo "${_DISTINCT_ID}"
|
||||
|
||||
- name: Check out repository
|
||||
if: ${{ !inputs.skip_checkout || false }}
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
|
||||
- name: Calculate version name
|
||||
id: calc-version-name
|
||||
env:
|
||||
_VERSION_NAME: ${{ inputs.version_name }}
|
||||
_PATCH_VERSION: ${{ inputs.patch_version }}
|
||||
run: |
|
||||
output() {
|
||||
local version_name=$1
|
||||
echo "version_name=$version_name" >> "$GITHUB_OUTPUT"
|
||||
}
|
||||
|
||||
# override version name if provided
|
||||
if [[ ! -z "${_VERSION_NAME}" ]]; then
|
||||
version_name=${_VERSION_NAME}
|
||||
echo "::warning::Override applied: $version_name"
|
||||
output "$version_name"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
current_year=$(date +%Y)
|
||||
current_month=$(date +%-m)
|
||||
|
||||
latest_tag_version=$(git tag -l --sort=-creatordate | grep "$APP_CODENAME" | head -n 1)
|
||||
if [[ -z "$latest_tag_version" ]]; then
|
||||
version_name="${current_year}.${current_month}.${_PATCH_VERSION:-0}"
|
||||
echo "::warning::No tags found, did you checkout? Calculating version from current date: $version_name"
|
||||
output "$version_name"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Git tag was found, calculate version from latest tag
|
||||
latest_version=${latest_tag_version:1} # remove 'v' from tag version
|
||||
|
||||
latest_major_version=$(echo "$latest_version" | cut -d "." -f 1)
|
||||
latest_minor_version=$(echo "$latest_version" | cut -d "." -f 2)
|
||||
patch_version=0
|
||||
if [[ ! -z "${_PATCH_VERSION}" ]]; then
|
||||
patch_version=${_PATCH_VERSION}
|
||||
echo "::warning::Patch Version Override applied: $patch_version"
|
||||
elif [[ "$current_year" == "$latest_major_version" && "$current_month" == "$latest_minor_version" ]]; then
|
||||
latest_patch_version=$(echo "$latest_version" | cut -d "." -f 3)
|
||||
patch_version=$(($latest_patch_version + 1))
|
||||
fi
|
||||
|
||||
version_name="${current_year}.${current_month}.${patch_version}"
|
||||
output "$version_name"
|
||||
|
||||
- name: Calculate version number
|
||||
id: calc-version-number
|
||||
env:
|
||||
_VERSION_NUMBER: ${{ inputs.version_number }}
|
||||
run: |
|
||||
# override version number if provided
|
||||
if [[ ! -z "${_VERSION_NUMBER}" ]]; then
|
||||
version_number=${_VERSION_NUMBER}
|
||||
echo "::warning::Override applied: $version_number"
|
||||
echo "version_number=$version_number" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
version_number=$(($GITHUB_RUN_NUMBER + ${BASE_VERSION_NUMBER}))
|
||||
echo "version_number=$version_number" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Create version info JSON
|
||||
env:
|
||||
_VERSION_NUMBER: ${{ steps.calc-version-number.outputs.version_number }}
|
||||
_VERSION_NAME: ${{ steps.calc-version-name.outputs.version_name }}
|
||||
run: |
|
||||
json=$(cat <<EOF
|
||||
{
|
||||
"version_number": "${_VERSION_NUMBER}",
|
||||
"version_name": "${_VERSION_NAME}"
|
||||
}
|
||||
EOF
|
||||
)
|
||||
echo "$json" > version_info.json
|
||||
|
||||
echo "## version-info.json" >> "$GITHUB_STEP_SUMMARY"
|
||||
echo '```json' >> "$GITHUB_STEP_SUMMARY"
|
||||
echo "$json" >> "$GITHUB_STEP_SUMMARY"
|
||||
echo '```' >> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
- name: Upload version info artifact
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: version-info
|
||||
path: version_info.json
|
||||
43
.github/workflows/build-authenticator.yml
vendored
43
.github/workflows/build-authenticator.yml
vendored
@@ -15,6 +15,9 @@ on:
|
||||
description: "Optional. Build number to use. Overrides default of GitHub run number."
|
||||
required: false
|
||||
type: number
|
||||
patch_version:
|
||||
description: "Order 999 - Overrides Patch version"
|
||||
type: boolean
|
||||
distribute-to-firebase:
|
||||
description: "Optional. Distribute artifacts to Firebase."
|
||||
required: false
|
||||
@@ -33,26 +36,27 @@ env:
|
||||
permissions:
|
||||
contents: read
|
||||
packages: read
|
||||
id-token: write
|
||||
|
||||
jobs:
|
||||
version:
|
||||
name: Calculate Version Name and Number
|
||||
uses: bitwarden/android/.github/workflows/_version.yml@main
|
||||
with:
|
||||
app_codename: "bwa"
|
||||
base_version_number: 0
|
||||
version_name: ${{ inputs.version-name }}
|
||||
version_number: ${{ inputs.version-code }}
|
||||
patch_version: ${{ inputs.patch_version && '999' || '' }}
|
||||
|
||||
build:
|
||||
name: Build Authenticator
|
||||
runs-on: ubuntu-24.04
|
||||
|
||||
steps:
|
||||
- name: Log inputs to job summary
|
||||
env:
|
||||
INPUTS: ${{ toJson(inputs) }}
|
||||
run: |
|
||||
{
|
||||
echo "<details><summary>Job Inputs</summary>"
|
||||
echo ""
|
||||
echo '```json'
|
||||
echo "$INPUTS"
|
||||
echo '```'
|
||||
echo "</details>"
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
uses: bitwarden/android/.github/actions/log-inputs@main
|
||||
with:
|
||||
inputs: "${{ toJson(inputs) }}"
|
||||
|
||||
- name: Check out repo
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
@@ -107,8 +111,11 @@ jobs:
|
||||
publish_playstore:
|
||||
name: Publish Authenticator Play Store artifacts
|
||||
needs:
|
||||
- version
|
||||
- build
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
id-token: write
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -236,8 +243,8 @@ jobs:
|
||||
- name: Increment version
|
||||
env:
|
||||
DEFAULT_VERSION_CODE: ${{ github.run_number }}
|
||||
INPUT_VERSION_CODE: "${{ inputs.version-code }}"
|
||||
INPUT_VERSION_NAME: ${{ inputs.version-name }}
|
||||
INPUT_VERSION_CODE: "${{ needs.version.outputs.version_number }}"
|
||||
INPUT_VERSION_NAME: ${{ needs.version.outputs.version_name }}
|
||||
run: |
|
||||
VERSION_CODE="${INPUT_VERSION_CODE:-$DEFAULT_VERSION_CODE}"
|
||||
VERSION_NAME_INPUT="${INPUT_VERSION_NAME:-}"
|
||||
@@ -278,7 +285,7 @@ jobs:
|
||||
|
||||
- name: Upload release Play Store .aab artifact
|
||||
if: ${{ matrix.variant == 'aab' }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.bitwarden.authenticator.aab
|
||||
path: authenticator/build/outputs/bundle/release/com.bitwarden.authenticator.aab
|
||||
@@ -286,7 +293,7 @@ jobs:
|
||||
|
||||
- name: Upload release .apk artifact
|
||||
if: ${{ matrix.variant == 'apk' }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.bitwarden.authenticator.apk
|
||||
path: authenticator/build/outputs/apk/release/com.bitwarden.authenticator.apk
|
||||
@@ -306,7 +313,7 @@ jobs:
|
||||
|
||||
- name: Upload .apk SHA file for release
|
||||
if: ${{ matrix.variant == 'apk' }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: authenticator-android-apk-sha256.txt
|
||||
path: ./authenticator-android-apk-sha256.txt
|
||||
@@ -314,7 +321,7 @@ jobs:
|
||||
|
||||
- name: Upload .aab SHA file for release
|
||||
if: ${{ matrix.variant == 'aab' }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: authenticator-android-aab-sha256.txt
|
||||
path: ./authenticator-android-aab-sha256.txt
|
||||
|
||||
78
.github/workflows/build.yml
vendored
78
.github/workflows/build.yml
vendored
@@ -15,6 +15,9 @@ on:
|
||||
description: "Optional. Build number to use. Overrides default of GitHub run number."
|
||||
required: false
|
||||
type: number
|
||||
patch_version:
|
||||
description: "Order 999 - Overrides Patch version"
|
||||
type: boolean
|
||||
distribute-to-firebase:
|
||||
description: "Optional. Distribute artifacts to Firebase."
|
||||
required: false
|
||||
@@ -34,26 +37,28 @@ env:
|
||||
permissions:
|
||||
contents: read
|
||||
packages: read
|
||||
id-token: write
|
||||
|
||||
jobs:
|
||||
version:
|
||||
name: Calculate Version Name and Number
|
||||
uses: bitwarden/android/.github/workflows/_version.yml@main
|
||||
with:
|
||||
app_codename: "bwpm"
|
||||
# Start from 11000 to prevent collisions with mobile build version codes
|
||||
base_version_number: 11000
|
||||
version_name: ${{ inputs.version-name }}
|
||||
version_number: ${{ inputs.version-code }}
|
||||
patch_version: ${{ inputs.patch_version && '999' || '' }}
|
||||
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-24.04
|
||||
|
||||
steps:
|
||||
- name: Log inputs to job summary
|
||||
env:
|
||||
INPUTS: ${{ toJson(inputs) }}
|
||||
run: |
|
||||
{
|
||||
echo "<details><summary>Job Inputs</summary>"
|
||||
echo ""
|
||||
echo '```json'
|
||||
echo "$INPUTS"
|
||||
echo '```'
|
||||
echo "</details>"
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
uses: bitwarden/android/.github/actions/log-inputs@main
|
||||
with:
|
||||
inputs: "${{ toJson(inputs) }}"
|
||||
|
||||
- name: Check out repo
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
@@ -106,7 +111,7 @@ jobs:
|
||||
run: bundle exec fastlane assembleDebugApks
|
||||
|
||||
- name: Upload test reports on failure
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
if: failure()
|
||||
with:
|
||||
name: test-reports
|
||||
@@ -115,8 +120,11 @@ jobs:
|
||||
publish_playstore:
|
||||
name: Publish Play Store artifacts
|
||||
needs:
|
||||
- version
|
||||
- build
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
id-token: write
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -230,10 +238,10 @@ jobs:
|
||||
|
||||
- name: Increment version
|
||||
env:
|
||||
VERSION_CODE: ${{ inputs.version-code }}
|
||||
VERSION_NAME: ${{ inputs.version-name }}
|
||||
VERSION_CODE: ${{ needs.version.outputs.version_number }}
|
||||
VERSION_NAME: ${{ needs.version.outputs.version_name }}
|
||||
run: |
|
||||
VERSION_CODE="${VERSION_CODE:-$((11000 + GITHUB_RUN_NUMBER))}"
|
||||
VERSION_CODE="${VERSION_CODE:-$GITHUB_RUN_NUMBER}"
|
||||
bundle exec fastlane setBuildVersionInfo \
|
||||
versionCode:$VERSION_CODE \
|
||||
versionName:$VERSION_NAME
|
||||
@@ -291,7 +299,7 @@ jobs:
|
||||
|
||||
- name: Upload release Play Store .aab artifact
|
||||
if: ${{ (matrix.variant == 'prod') && (matrix.artifact == 'aab') }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden.aab
|
||||
path: app/build/outputs/bundle/standardRelease/com.x8bit.bitwarden.aab
|
||||
@@ -299,7 +307,7 @@ jobs:
|
||||
|
||||
- name: Upload beta Play Store .aab artifact
|
||||
if: ${{ (matrix.variant == 'prod') && (matrix.artifact == 'aab') }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden.beta.aab
|
||||
path: app/build/outputs/bundle/standardBeta/com.x8bit.bitwarden.beta.aab
|
||||
@@ -307,7 +315,7 @@ jobs:
|
||||
|
||||
- name: Upload release .apk artifact
|
||||
if: ${{ (matrix.variant == 'prod') && (matrix.artifact == 'apk') }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden.apk
|
||||
path: app/build/outputs/apk/standard/release/com.x8bit.bitwarden.apk
|
||||
@@ -315,7 +323,7 @@ jobs:
|
||||
|
||||
- name: Upload beta .apk artifact
|
||||
if: ${{ (matrix.variant == 'prod') && (matrix.artifact == 'apk') }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden.beta.apk
|
||||
path: app/build/outputs/apk/standard/beta/com.x8bit.bitwarden.beta.apk
|
||||
@@ -324,7 +332,7 @@ jobs:
|
||||
# When building variants other than 'prod'
|
||||
- name: Upload debug .apk artifact
|
||||
if: ${{ (matrix.variant != 'prod') && (matrix.artifact == 'apk') }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden.${{ matrix.variant }}.apk
|
||||
path: app/build/outputs/apk/standard/debug/com.x8bit.bitwarden.dev.apk
|
||||
@@ -362,7 +370,7 @@ jobs:
|
||||
|
||||
- name: Upload .apk SHA file for release
|
||||
if: ${{ (matrix.variant == 'prod') && (matrix.artifact == 'apk') }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden.apk-sha256.txt
|
||||
path: ./com.x8bit.bitwarden.apk-sha256.txt
|
||||
@@ -370,7 +378,7 @@ jobs:
|
||||
|
||||
- name: Upload .apk SHA file for beta
|
||||
if: ${{ (matrix.variant == 'prod') && (matrix.artifact == 'apk') }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden.beta.apk-sha256.txt
|
||||
path: ./com.x8bit.bitwarden.beta.apk-sha256.txt
|
||||
@@ -378,7 +386,7 @@ jobs:
|
||||
|
||||
- name: Upload .aab SHA file for release
|
||||
if: ${{ (matrix.variant == 'prod') && (matrix.artifact == 'aab') }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden.aab-sha256.txt
|
||||
path: ./com.x8bit.bitwarden.aab-sha256.txt
|
||||
@@ -386,7 +394,7 @@ jobs:
|
||||
|
||||
- name: Upload .aab SHA file for beta
|
||||
if: ${{ (matrix.variant == 'prod') && (matrix.artifact == 'aab') }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden.beta.aab-sha256.txt
|
||||
path: ./com.x8bit.bitwarden.beta.aab-sha256.txt
|
||||
@@ -394,7 +402,7 @@ jobs:
|
||||
|
||||
- name: Upload .apk SHA file for debug
|
||||
if: ${{ (matrix.variant != 'prod') && (matrix.artifact == 'apk') }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden.${{ matrix.variant }}.apk-sha256.txt
|
||||
path: ./com.x8bit.bitwarden.${{ matrix.variant }}.apk-sha256.txt
|
||||
@@ -436,8 +444,11 @@ jobs:
|
||||
publish_fdroid:
|
||||
name: Publish F-Droid artifacts
|
||||
needs:
|
||||
- version
|
||||
- build
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Check out repo
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
@@ -530,13 +541,12 @@ jobs:
|
||||
"$GITHUB_RUN_ID" \
|
||||
"$GITHUB_RUN_ATTEMPT"
|
||||
|
||||
# Start from 11000 to prevent collisions with mobile build version codes
|
||||
- name: Increment version
|
||||
env:
|
||||
VERSION_CODE: ${{ inputs.version-code }}
|
||||
VERSION_NAME: ${{ inputs.version-name }}
|
||||
VERSION_CODE: ${{ needs.version.outputs.version_number }}
|
||||
VERSION_NAME: ${{ needs.version.outputs.version_name }}
|
||||
run: |
|
||||
VERSION_CODE="${VERSION_CODE:-$((11000 + GITHUB_RUN_NUMBER))}"
|
||||
VERSION_CODE="${VERSION_CODE:-$GITHUB_RUN_NUMBER}"
|
||||
bundle exec fastlane setBuildVersionInfo \
|
||||
versionCode:$VERSION_CODE \
|
||||
versionName:$VERSION_NAME
|
||||
@@ -569,7 +579,7 @@ jobs:
|
||||
keyPassword:$FDROID_BETA_KEY_PASSWORD
|
||||
|
||||
- name: Upload F-Droid .apk artifact
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden-fdroid.apk
|
||||
path: app/build/outputs/apk/fdroid/release/com.x8bit.bitwarden-fdroid.apk
|
||||
@@ -581,14 +591,14 @@ jobs:
|
||||
> ./com.x8bit.bitwarden-fdroid.apk-sha256.txt
|
||||
|
||||
- name: Upload F-Droid SHA file
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden-fdroid.apk-sha256.txt
|
||||
path: ./com.x8bit.bitwarden-fdroid.apk-sha256.txt
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Upload F-Droid Beta .apk artifact
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden.beta-fdroid.apk
|
||||
path: app/build/outputs/apk/fdroid/beta/com.x8bit.bitwarden.beta-fdroid.apk
|
||||
@@ -600,7 +610,7 @@ jobs:
|
||||
> ./com.x8bit.bitwarden.beta-fdroid.apk-sha256.txt
|
||||
|
||||
- name: Upload F-Droid Beta SHA file
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: com.x8bit.bitwarden.beta-fdroid.apk-sha256.txt
|
||||
path: ./com.x8bit.bitwarden.beta-fdroid.apk-sha256.txt
|
||||
|
||||
38
.github/workflows/publish-store.yml
vendored
38
.github/workflows/publish-store.yml
vendored
@@ -37,6 +37,7 @@ on:
|
||||
type: choice
|
||||
options:
|
||||
- internal
|
||||
- qa
|
||||
- Fastlane Automation Source
|
||||
required: true
|
||||
default: "internal"
|
||||
@@ -44,8 +45,8 @@ on:
|
||||
description: "Track to promote to."
|
||||
type: choice
|
||||
options:
|
||||
- production
|
||||
- Fastlane Automation Target
|
||||
- Unused
|
||||
- Unused2
|
||||
required: true
|
||||
dry-run:
|
||||
description: "Dry-Run, Run the workflow without publishing to the store"
|
||||
@@ -68,17 +69,9 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Log inputs to job summary
|
||||
env:
|
||||
INPUTS: ${{ toJson(inputs) }}
|
||||
run: |
|
||||
{
|
||||
echo "<details><summary>Job Inputs</summary>"
|
||||
echo ""
|
||||
echo '```json'
|
||||
echo "$INPUTS"
|
||||
echo '```'
|
||||
echo "</details>"
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
uses: bitwarden/android/.github/actions/log-inputs@main
|
||||
with:
|
||||
inputs: "${{ toJson(inputs) }}"
|
||||
|
||||
- name: Check out repo
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
@@ -161,11 +154,6 @@ jobs:
|
||||
|
||||
decimal=$(echo "scale=2; ${ROLLOUT_PERCENTAGE/\%/} / 100" | bc)
|
||||
|
||||
bundle exec fastlane updateReleaseNotes \
|
||||
releaseNotes:"$RELEASE_NOTES" \
|
||||
versionCode:"$VERSION_CODE" \
|
||||
packageName:"$PACKAGE_NAME"
|
||||
|
||||
bundle exec fastlane promoteToProduction \
|
||||
versionCode:"$VERSION_CODE" \
|
||||
versionName:"$VERSION_NAME" \
|
||||
@@ -174,17 +162,3 @@ jobs:
|
||||
releaseNotes:"$RELEASE_NOTES" \
|
||||
track:"$TRACK_FROM" \
|
||||
trackPromoteTo:"$TRACK_TARGET"
|
||||
|
||||
- name: Enable Publish Github Release Workflow
|
||||
env:
|
||||
PRODUCT: ${{ inputs.product }}
|
||||
run: |
|
||||
if ${{ inputs.dry-run }} ; then
|
||||
gh workflow view publish-github-release-bwpm.yml
|
||||
exit 0
|
||||
fi
|
||||
if [ "$PRODUCT" = "Password Manager" ]; then
|
||||
gh workflow enable publish-github-release-bwpm.yml
|
||||
elif [ "$PRODUCT" = "Authenticator" ]; then
|
||||
gh workflow enable publish-github-release-bwa.yml
|
||||
fi
|
||||
|
||||
28
.github/workflows/respond.yml
vendored
Normal file
28
.github/workflows/respond.yml
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
name: Respond
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
pull_request_review_comment:
|
||||
types: [created]
|
||||
issues:
|
||||
types: [opened, assigned]
|
||||
pull_request_review:
|
||||
types: [submitted]
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
respond:
|
||||
name: Respond
|
||||
uses: bitwarden/gh-actions/.github/workflows/_respond.yml@main
|
||||
secrets:
|
||||
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
|
||||
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
|
||||
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
|
||||
permissions:
|
||||
actions: read
|
||||
contents: write
|
||||
id-token: write
|
||||
issues: write
|
||||
pull-requests: write
|
||||
21
.github/workflows/review-code.yml
vendored
Normal file
21
.github/workflows/review-code.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
name: Code Review
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, ready_for_review]
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
review:
|
||||
name: Review
|
||||
uses: bitwarden/gh-actions/.github/workflows/_review-code.yml@main
|
||||
secrets:
|
||||
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
|
||||
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
|
||||
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
id-token: write
|
||||
pull-requests: write
|
||||
80
.github/workflows/sdlc-label-pr.yml
vendored
Normal file
80
.github/workflows/sdlc-label-pr.yml
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
name: SDLC / Label PR by Files
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
pr-number:
|
||||
description: "Pull Request Number"
|
||||
required: true
|
||||
type: number
|
||||
mode:
|
||||
description: "Labeling Mode"
|
||||
type: choice
|
||||
options:
|
||||
- add
|
||||
- replace
|
||||
default: add
|
||||
dry-run:
|
||||
description: "Dry Run - Don't apply labels"
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
jobs:
|
||||
label-pr:
|
||||
name: Label PR by Changed Files
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
pull-requests: write # required to update labels
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Determine label mode for Pull Request
|
||||
id: label-mode
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
_PR_NUMBER: ${{ inputs.pr-number }}
|
||||
_PR_USER: ${{ github.event.pull_request.user.login }}
|
||||
_IS_FORK: ${{ github.event.pull_request.head.repo.fork }}
|
||||
run: |
|
||||
# Support workflow_dispatch testing by retrieving PR data
|
||||
if [ -z "$_PR_USER" ]; then
|
||||
echo "👀 PR User is empty, retrieving PR data for PR #$_PR_NUMBER..."
|
||||
PR_DATA=$(gh pr view "$_PR_NUMBER" --json author,isCrossRepository)
|
||||
_PR_USER=$(echo "$PR_DATA" | jq -r '.author.login')
|
||||
_IS_FORK=$(echo "$PR_DATA" | jq -r '.isCrossRepository')
|
||||
fi
|
||||
|
||||
echo "📋 PR User: $_PR_USER"
|
||||
echo "📋 Is Fork: $_IS_FORK"
|
||||
|
||||
# Handle PRs with labels set by other automations by adding instead of replacing
|
||||
if [ "$_IS_FORK" = "true" ]; then
|
||||
echo "➡️ Fork PR ($_PR_USER). Label mode: --add"
|
||||
echo "label_mode=--add" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$_PR_USER" = "renovate[bot]" ] || [ "$_PR_USER" = "bw-ghapp[bot]" ]; then
|
||||
echo "➡️ Bot PR ($_PR_USER). Label mode: --add"
|
||||
echo "label_mode=--add" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "➡️ Normal PR. Label mode: --replace"
|
||||
echo "label_mode=--replace" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Label PR based on changed files
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
_PR_NUMBER: ${{ inputs.pr-number || github.event.pull_request.number }}
|
||||
_LABEL_MODE: ${{ inputs.mode && format('--{0}', inputs.mode) || steps.label-mode.outputs.label_mode }}
|
||||
_DRY_RUN: ${{ inputs.dry-run == true && '--dry-run' || '' }}
|
||||
run: |
|
||||
echo "🔍 Labeling PR #$_PR_NUMBER with mode: $_LABEL_MODE and dry-run: $_DRY_RUN"
|
||||
python3 .github/scripts/label-pr.py "$_PR_NUMBER" "$_LABEL_MODE" "$_DRY_RUN"
|
||||
|
||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -76,7 +76,7 @@ jobs:
|
||||
bundle exec fastlane check
|
||||
|
||||
- name: Upload test reports
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
if: always()
|
||||
with:
|
||||
name: test-reports
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
npx lint-staged
|
||||
20
Gemfile.lock
20
Gemfile.lock
@@ -11,8 +11,8 @@ GEM
|
||||
artifactory (3.0.17)
|
||||
atomos (0.1.3)
|
||||
aws-eventstream (1.4.0)
|
||||
aws-partitions (1.1172.0)
|
||||
aws-sdk-core (3.233.0)
|
||||
aws-partitions (1.1181.0)
|
||||
aws-sdk-core (3.236.0)
|
||||
aws-eventstream (~> 1, >= 1.3.0)
|
||||
aws-partitions (~> 1, >= 1.992.0)
|
||||
aws-sigv4 (~> 1.9)
|
||||
@@ -20,11 +20,11 @@ GEM
|
||||
bigdecimal
|
||||
jmespath (~> 1, >= 1.6.1)
|
||||
logger
|
||||
aws-sdk-kms (1.113.0)
|
||||
aws-sdk-core (~> 3, >= 3.231.0)
|
||||
aws-sdk-kms (1.117.0)
|
||||
aws-sdk-core (~> 3, >= 3.234.0)
|
||||
aws-sigv4 (~> 1.5)
|
||||
aws-sdk-s3 (1.199.1)
|
||||
aws-sdk-core (~> 3, >= 3.231.0)
|
||||
aws-sdk-s3 (1.203.0)
|
||||
aws-sdk-core (~> 3, >= 3.234.0)
|
||||
aws-sdk-kms (~> 1)
|
||||
aws-sigv4 (~> 1.5)
|
||||
aws-sigv4 (1.12.1)
|
||||
@@ -38,7 +38,7 @@ GEM
|
||||
commander (4.6.0)
|
||||
highline (~> 2.0.0)
|
||||
csv (3.3.5)
|
||||
date (3.4.1)
|
||||
date (3.5.0)
|
||||
declarative (0.0.20)
|
||||
digest-crc (0.7.0)
|
||||
rake (>= 12.0.0, < 14.0.0)
|
||||
@@ -169,7 +169,7 @@ GEM
|
||||
httpclient (2.9.0)
|
||||
mutex_m
|
||||
jmespath (1.6.2)
|
||||
json (2.15.1)
|
||||
json (2.16.0)
|
||||
jwt (2.10.2)
|
||||
base64
|
||||
logger (1.7.0)
|
||||
@@ -181,12 +181,12 @@ GEM
|
||||
nanaimo (0.4.0)
|
||||
naturally (2.3.0)
|
||||
nkf (0.2.0)
|
||||
optparse (0.6.0)
|
||||
optparse (0.8.0)
|
||||
os (1.1.4)
|
||||
ostruct (0.6.3)
|
||||
plist (3.7.2)
|
||||
public_suffix (6.0.2)
|
||||
rake (13.3.0)
|
||||
rake (13.3.1)
|
||||
representable (3.2.0)
|
||||
declarative (< 0.1.0)
|
||||
trailblazer-option (>= 0.1.1, < 0.2.0)
|
||||
|
||||
24
README.md
24
README.md
@@ -4,13 +4,12 @@
|
||||
|
||||
- [Compatibility](#compatibility)
|
||||
- [Setup](#setup)
|
||||
- [Theme](#theme)
|
||||
- [Dependencies](#dependencies)
|
||||
|
||||
## Compatibility
|
||||
|
||||
- **Minimum SDK**: 29
|
||||
- **Target SDK**: 35
|
||||
- **Minimum SDK**: 29 (Android 10)
|
||||
- **Target SDK**: 36 (Android 16)
|
||||
- **Device Types Supported**: Phone and Tablet
|
||||
- **Orientations Supported**: Portrait and Landscape
|
||||
|
||||
@@ -93,25 +92,6 @@ chmod +x .git/hooks/pre-commit
|
||||
echo "detekt pre-commit hook installed successfully to .git/hooks/pre-commit"
|
||||
```
|
||||
|
||||
## Theme
|
||||
|
||||
### Icons & Illustrations
|
||||
|
||||
The app supports light mode, dark mode and dynamic colors. Most icons in the app will display correctly using tinting but multi-tonal icons and illustrations require extra processing in order to be displayed properly with dynamic colors.
|
||||
|
||||
All illustrations and multi-tonal icons require the svg paths to be tagged with the `name` attribute in order for each individual path to be tinted the appropriate color. Any untagged path will not be tinted and the resulting image will be incorrect.
|
||||
|
||||
The supported tags are as follows:
|
||||
|
||||
* outline
|
||||
* primary
|
||||
* secondary
|
||||
* tertiary
|
||||
* accent
|
||||
* logo
|
||||
* navigation
|
||||
* navigationActiveAccent
|
||||
|
||||
## Dependencies
|
||||
|
||||
### Application Dependencies
|
||||
|
||||
@@ -220,7 +220,7 @@ dependencies {
|
||||
add("standardImplementation", dependencyNotation)
|
||||
}
|
||||
|
||||
implementation(files("libs/authenticatorbridge-1.0.1-release.aar"))
|
||||
implementation(project(":authenticatorbridge"))
|
||||
|
||||
implementation(project(":annotation"))
|
||||
implementation(project(":core"))
|
||||
@@ -235,6 +235,7 @@ dependencies {
|
||||
implementation(libs.androidx.browser)
|
||||
implementation(libs.androidx.biometrics)
|
||||
implementation(libs.androidx.camera.camera2)
|
||||
implementation(libs.androidx.camera.compose)
|
||||
implementation(platform(libs.androidx.compose.bom))
|
||||
implementation(libs.androidx.compose.animation)
|
||||
implementation(libs.androidx.compose.material3)
|
||||
@@ -281,6 +282,7 @@ dependencies {
|
||||
standardImplementation(libs.google.play.review)
|
||||
|
||||
// Pull in test fixtures from other modules
|
||||
testImplementation(testFixtures(project(":core")))
|
||||
testImplementation(testFixtures(project(":data")))
|
||||
testImplementation(testFixtures(project(":network")))
|
||||
testImplementation(testFixtures(project(":ui")))
|
||||
@@ -302,7 +304,10 @@ tasks {
|
||||
useJUnitPlatform()
|
||||
maxHeapSize = "2g"
|
||||
maxParallelForks = Runtime.getRuntime().availableProcessors()
|
||||
jvmArgs = jvmArgs.orEmpty() + "-XX:+UseParallelGC" + "-Duser.country=US"
|
||||
jvmArgs = jvmArgs.orEmpty() + "-XX:+UseParallelGC" +
|
||||
// Explicitly setting the user Country and Language because tests assume en-US
|
||||
"-Duser.country=US" +
|
||||
"-Duser.language=en"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<credential-provider>
|
||||
<capabilities>
|
||||
<capability name="android.credentials.TYPE_PASSWORD_CREDENTIAL" />
|
||||
<capability name="androidx.credentials.TYPE_PUBLIC_KEY_CREDENTIAL" />
|
||||
</capabilities>
|
||||
</credential-provider>
|
||||
@@ -0,0 +1,44 @@
|
||||
Recognized as best password manager by PCMag, WIRED, The Verge, CNET, G2, and more!
|
||||
|
||||
SECURE YOUR DIGITAL LIFE
|
||||
Secure your digital life and protect against data breaches by generating and saving unique, strong passwords for every account. Maintain everything in an end-to-end encrypted password vault that only you can access.
|
||||
|
||||
ACCESS YOUR DATA, ANYWHERE, ANYTIME, ON ANY DEVICE
|
||||
Easily manage, store, secure, and share unlimited passwords and passkeys across unlimited devices without restrictions.
|
||||
|
||||
USE PASSKEYS WHEREVER YOU LOG IN
|
||||
Create, store, and sync passkeys across the Bitwarden mobile app and browser extensions for a secure, passwordless experience no matter what device you're on.
|
||||
|
||||
EVERYONE SHOULD HAVE THE TOOLS TO STAY SAFE ONLINE
|
||||
Utilize Bitwarden for free with no ads or selling data. Bitwarden believes everyone should have the ability to stay safe online. Premium plans offer access to advanced features.
|
||||
|
||||
EMPOWER YOUR TEAMS WITH BITWARDEN
|
||||
Plans for Teams and Enterprise come with professional business features. Some examples include SSO integration, self-hosting, directory integration and SCIM provisioning, global policies, API access, event logs, and more.
|
||||
|
||||
Use Bitwarden to secure your workforce and share sensitive information with colleagues.
|
||||
|
||||
More reasons to choose Bitwarden:
|
||||
|
||||
World-Class Encryption
|
||||
Passwords are protected with advanced end-to-end encryption (AES-256 bit, salted hashing, and PBKDF2 SHA-256) so your data stays secure and private.
|
||||
|
||||
3rd-party Audits
|
||||
Bitwarden regularly conducts comprehensive third-party security audits with notable security firms. These annual audits include source code assessments and penetration testing across Bitwarden IPs, servers, and web applications.
|
||||
|
||||
Advanced 2FA
|
||||
Secure your login with a third-party authenticator, emailed codes, or FIDO2 WebAuthn credentials such as a hardware security key or passkey.
|
||||
|
||||
Bitwarden Send
|
||||
Transmit data directly to others while maintaining end-to-end encrypted security and limiting exposure.
|
||||
|
||||
Built-in Generator
|
||||
Create long, complex, and distinct passwords and unique usernames for every site you visit. Integrate with email alias providers for additional privacy.
|
||||
|
||||
Global Translations
|
||||
Bitwarden translations exist for more than 50 languages.
|
||||
|
||||
Cross-Platform Applications
|
||||
Secure and share sensitive data within your Bitwarden Vault from any browser, mobile device, or desktop OS, and more.
|
||||
|
||||
|
||||
Accessibility Services Disclosure: Bitwarden offers the ability to use the Accessibility Service to augment Autofill on older devices or in cases where autofill is not working correctly. When enabled, the Accessibility Service is used to search for login fields in apps and websites. This establishes the appropriate field IDs when a match for the app or site is found and inserts credentials. When the Accessibility Service is active Bitwarden does not store information or control any on-screen elements beyond inserting credentials.
|
||||
@@ -0,0 +1 @@
|
||||
Bitwarden is a login and password manager that helps keep you safe while online.
|
||||
1
app/src/fdroid/fastlane/metadata/android/en-US/title.txt
Normal file
1
app/src/fdroid/fastlane/metadata/android/en-US/title.txt
Normal file
@@ -0,0 +1 @@
|
||||
Bitwarden Password Manager
|
||||
@@ -86,6 +86,7 @@
|
||||
<intent-filter>
|
||||
<action android:name="com.x8bit.bitwarden.credentials.ACTION_CREATE_PASSKEY" />
|
||||
<action android:name="com.x8bit.bitwarden.credentials.ACTION_GET_PASSKEY" />
|
||||
<action android:name="com.x8bit.bitwarden.credentials.ACTION_CREATE_PASSWORD" />
|
||||
<action android:name="com.x8bit.bitwarden.credentials.ACTION_GET_PASSWORD" />
|
||||
<action android:name="com.x8bit.bitwarden.credentials.ACTION_UNLOCK_ACCOUNT" />
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import com.x8bit.bitwarden.ui.platform.composition.LocalManagerProvider
|
||||
import com.x8bit.bitwarden.ui.platform.feature.debugmenu.debugMenuDestination
|
||||
import com.x8bit.bitwarden.ui.platform.feature.debugmenu.manager.DebugMenuLaunchManager
|
||||
import com.x8bit.bitwarden.ui.platform.feature.debugmenu.navigateToDebugMenuScreen
|
||||
import com.x8bit.bitwarden.ui.platform.feature.rootnav.ROOT_ROUTE
|
||||
import com.x8bit.bitwarden.ui.platform.feature.rootnav.RootNavigationRoute
|
||||
import com.x8bit.bitwarden.ui.platform.feature.rootnav.rootNavDestination
|
||||
import com.x8bit.bitwarden.ui.platform.feature.settings.appearance.model.AppLanguage
|
||||
import com.x8bit.bitwarden.ui.platform.model.AuthTabLaunchers
|
||||
@@ -119,11 +119,11 @@ class MainActivity : AppCompatActivity() {
|
||||
) {
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = ROOT_ROUTE,
|
||||
startDestination = RootNavigationRoute,
|
||||
) {
|
||||
// Nothing else should end up at this top level, we just want the ability
|
||||
// to have the debug menu appear on top of the rest of the app without
|
||||
// interacting with the state-based navigation used by the RootNavScreen.
|
||||
// Both root navigation and debug menu exist at this top level.
|
||||
// The debug menu can appear on top of the rest of the app without
|
||||
// interacting with the state-based navigation used by RootNavScreen.
|
||||
rootNavDestination { shouldShowSplashScreen = false }
|
||||
debugMenuDestination(
|
||||
onNavigateBack = { navController.popBackStack() },
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.bitwarden.cxf.util.getProviderImportCredentialsRequest
|
||||
import com.bitwarden.ui.platform.base.BaseViewModel
|
||||
import com.bitwarden.ui.platform.feature.settings.appearance.model.AppTheme
|
||||
import com.bitwarden.ui.platform.manager.share.ShareManager
|
||||
import com.bitwarden.ui.platform.model.TotpData
|
||||
import com.bitwarden.ui.platform.resource.BitwardenString
|
||||
import com.bitwarden.vault.CipherView
|
||||
import com.x8bit.bitwarden.data.auth.manager.AddTotpItemFromAuthenticatorManager
|
||||
@@ -46,7 +47,6 @@ import com.x8bit.bitwarden.ui.platform.model.FeatureFlagsState
|
||||
import com.x8bit.bitwarden.ui.platform.util.isAccountSecurityShortcut
|
||||
import com.x8bit.bitwarden.ui.platform.util.isMyVaultShortcut
|
||||
import com.x8bit.bitwarden.ui.platform.util.isPasswordGeneratorShortcut
|
||||
import com.x8bit.bitwarden.ui.vault.model.TotpData
|
||||
import com.x8bit.bitwarden.ui.vault.util.getTotpDataOrNull
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
|
||||
@@ -211,30 +211,64 @@ interface AuthDiskSource : AppIdProvider {
|
||||
/**
|
||||
* Gets the flow for the biometrics key for the given [userId].
|
||||
*/
|
||||
fun getUserBiometicUnlockKeyFlow(userId: String): Flow<String?>
|
||||
fun getUserBiometricUnlockKeyFlow(userId: String): Flow<String?>
|
||||
|
||||
/**
|
||||
* Retrieves a pin-protected user key for the given [userId].
|
||||
*/
|
||||
@Deprecated(
|
||||
message = "Use getPinProtectedUserKeyEnvelope instead.",
|
||||
replaceWith = ReplaceWith("getPinProtectedUserKeyEnvelope"),
|
||||
)
|
||||
fun getPinProtectedUserKey(userId: String): String?
|
||||
|
||||
/**
|
||||
* Retrieves a pin-protected user key envelope for the given [userId].
|
||||
*/
|
||||
fun getPinProtectedUserKeyEnvelope(userId: String): String?
|
||||
|
||||
/**
|
||||
* Stores a pin-protected user key for the given [userId].
|
||||
*
|
||||
* When [inMemoryOnly] is `true`, the value will only be available via a call to
|
||||
* [getPinProtectedUserKey] during the current app session.
|
||||
*/
|
||||
@Deprecated(
|
||||
message = "Use storePinProtectedUserKeyEnvelope instead.",
|
||||
replaceWith = ReplaceWith("storePinProtectedUserKeyEnvelope"),
|
||||
)
|
||||
fun storePinProtectedUserKey(
|
||||
userId: String,
|
||||
pinProtectedUserKey: String?,
|
||||
inMemoryOnly: Boolean = false,
|
||||
)
|
||||
|
||||
/**
|
||||
* Stores a pin-protected user key envelope for the given [userId].
|
||||
*
|
||||
* When [inMemoryOnly] is `true`, the value will only be available via a call to
|
||||
* [getPinProtectedUserKeyEnvelope] during the current app session.
|
||||
*/
|
||||
fun storePinProtectedUserKeyEnvelope(
|
||||
userId: String,
|
||||
pinProtectedUserKeyEnvelope: String?,
|
||||
inMemoryOnly: Boolean = false,
|
||||
)
|
||||
|
||||
/**
|
||||
* Retrieves a flow for the pin-protected user key for the given [userId].
|
||||
*/
|
||||
@Deprecated(
|
||||
message = "Use getPinProtectedUserKeyEnvelopeFlow instead.",
|
||||
replaceWith = ReplaceWith("getPinProtectedUserKeyEnvelopeFlow"),
|
||||
)
|
||||
fun getPinProtectedUserKeyFlow(userId: String): Flow<String?>
|
||||
|
||||
/**
|
||||
* Retrieves a flow for the pin-protected user key envelope for the given [userId].
|
||||
*/
|
||||
fun getPinProtectedUserKeyEnvelopeFlow(userId: String): Flow<String?>
|
||||
|
||||
/**
|
||||
* Gets a two-factor auth token using a user's [email].
|
||||
*/
|
||||
|
||||
@@ -37,6 +37,7 @@ private const val INVALID_UNLOCK_ATTEMPTS_KEY = "invalidUnlockAttempts"
|
||||
private const val MASTER_KEY_ENCRYPTION_USER_KEY = "masterKeyEncryptedUserKey"
|
||||
private const val MASTER_KEY_ENCRYPTION_PRIVATE_KEY = "encPrivateKey"
|
||||
private const val PIN_PROTECTED_USER_KEY_KEY = "pinKeyEncryptedUserKey"
|
||||
private const val PIN_PROTECTED_USER_KEY_KEY_ENVELOPE = "pinKeyEncryptedUserKeyEnvelope"
|
||||
private const val ENCRYPTED_PIN_KEY = "protectedPin"
|
||||
private const val ORGANIZATIONS_KEY = "organizations"
|
||||
private const val ORGANIZATION_KEYS_KEY = "encOrgKeys"
|
||||
@@ -67,6 +68,7 @@ class AuthDiskSourceImpl(
|
||||
AuthDiskSource {
|
||||
|
||||
private val inMemoryPinProtectedUserKeys = mutableMapOf<String, String?>()
|
||||
private val inMemoryPinProtectedUserKeyEnvelopes = mutableMapOf<String, String?>()
|
||||
private val mutableShouldUseKeyConnectorFlowMap =
|
||||
mutableMapOf<String, MutableSharedFlow<Boolean?>>()
|
||||
private val mutableOrganizationsFlowMap =
|
||||
@@ -82,6 +84,8 @@ class AuthDiskSourceImpl(
|
||||
mutableMapOf<String, MutableSharedFlow<String?>>()
|
||||
private val mutablePinProtectedUserKeyFlowMap =
|
||||
mutableMapOf<String, MutableSharedFlow<String?>>()
|
||||
private val mutablePinProtectedUserKeyEnvelopeFlowMap =
|
||||
mutableMapOf<String, MutableSharedFlow<String?>>()
|
||||
private val mutableUserStateFlow = bufferedMutableSharedFlow<UserStateJson?>(replay = 1)
|
||||
|
||||
override var userState: UserStateJson?
|
||||
@@ -141,8 +145,6 @@ class AuthDiskSourceImpl(
|
||||
storeInvalidUnlockAttempts(userId = userId, invalidUnlockAttempts = null)
|
||||
storeUserKey(userId = userId, userKey = null)
|
||||
storeUserAutoUnlockKey(userId = userId, userAutoUnlockKey = null)
|
||||
storePinProtectedUserKey(userId = userId, pinProtectedUserKey = null)
|
||||
storeEncryptedPin(userId = userId, encryptedPin = null)
|
||||
storePrivateKey(userId = userId, privateKey = null)
|
||||
storeAccountKeys(userId = userId, accountKeys = null)
|
||||
storeOrganizationKeys(userId = userId, organizationKeys = null)
|
||||
@@ -158,9 +160,13 @@ class AuthDiskSourceImpl(
|
||||
storeShowImportLogins(userId = userId, showImportLogins = null)
|
||||
storeLastLockTimestamp(userId = userId, lastLockTimestamp = null)
|
||||
|
||||
// Do not remove the DeviceKey or PendingAuthRequest on logout, these are persisted
|
||||
// indefinitely unless the TDE flow explicitly removes them.
|
||||
// Do not remove OnboardingStatus we want to keep track of this even after logout.
|
||||
// Certain values are never removed as required by the feature requirements:
|
||||
// * EncryptedPin
|
||||
// * PinProtectedUserKey
|
||||
// * PinProtectedUserKeyEnvelope
|
||||
// * DeviceKey
|
||||
// * PendingAuthRequest
|
||||
// * OnboardingStatus
|
||||
}
|
||||
|
||||
override fun getAuthenticatorSyncUnlockKey(userId: String): String? =
|
||||
@@ -325,14 +331,28 @@ class AuthDiskSourceImpl(
|
||||
getMutableBiometricUnlockKeyFlow(userId).tryEmit(biometricsKey)
|
||||
}
|
||||
|
||||
override fun getUserBiometicUnlockKeyFlow(userId: String): Flow<String?> =
|
||||
override fun getUserBiometricUnlockKeyFlow(userId: String): Flow<String?> =
|
||||
getMutableBiometricUnlockKeyFlow(userId)
|
||||
.onSubscription { emit(getUserBiometricUnlockKey(userId = userId)) }
|
||||
|
||||
@Deprecated(
|
||||
"Use getPinProtectedUserKeyEnvelope instead.",
|
||||
replaceWith = ReplaceWith("getPinProtectedUserKeyEnvelope"),
|
||||
)
|
||||
override fun getPinProtectedUserKey(userId: String): String? =
|
||||
inMemoryPinProtectedUserKeys[userId]
|
||||
?: getString(key = PIN_PROTECTED_USER_KEY_KEY.appendIdentifier(userId))
|
||||
|
||||
override fun getPinProtectedUserKeyEnvelope(userId: String): String? =
|
||||
inMemoryPinProtectedUserKeyEnvelopes[userId]
|
||||
?: getString(
|
||||
key = PIN_PROTECTED_USER_KEY_KEY_ENVELOPE.appendIdentifier(userId),
|
||||
)
|
||||
|
||||
@Deprecated(
|
||||
"Use storePinProtectedUserKeyEnvelope instead.",
|
||||
replaceWith = ReplaceWith("storePinProtectedUserKeyEnvelope"),
|
||||
)
|
||||
override fun storePinProtectedUserKey(
|
||||
userId: String,
|
||||
pinProtectedUserKey: String?,
|
||||
@@ -347,10 +367,32 @@ class AuthDiskSourceImpl(
|
||||
getMutablePinProtectedUserKeyFlow(userId).tryEmit(pinProtectedUserKey)
|
||||
}
|
||||
|
||||
override fun storePinProtectedUserKeyEnvelope(
|
||||
userId: String,
|
||||
pinProtectedUserKeyEnvelope: String?,
|
||||
inMemoryOnly: Boolean,
|
||||
) {
|
||||
inMemoryPinProtectedUserKeyEnvelopes[userId] = pinProtectedUserKeyEnvelope
|
||||
if (inMemoryOnly) return
|
||||
putString(
|
||||
key = PIN_PROTECTED_USER_KEY_KEY_ENVELOPE.appendIdentifier(userId),
|
||||
value = pinProtectedUserKeyEnvelope,
|
||||
)
|
||||
getMutablePinProtectedUserKeyEnvelopeFlow(userId).tryEmit(pinProtectedUserKeyEnvelope)
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
"Use getPinProtectedUserKeyEnvelopeFlow instead.",
|
||||
replaceWith = ReplaceWith("getPinProtectedUserKeyEnvelopeFlow"),
|
||||
)
|
||||
override fun getPinProtectedUserKeyFlow(userId: String): Flow<String?> =
|
||||
getMutablePinProtectedUserKeyFlow(userId)
|
||||
.onSubscription { emit(getPinProtectedUserKey(userId = userId)) }
|
||||
|
||||
override fun getPinProtectedUserKeyEnvelopeFlow(userId: String): Flow<String?> =
|
||||
getMutablePinProtectedUserKeyEnvelopeFlow(userId)
|
||||
.onSubscription { emit(getPinProtectedUserKeyEnvelope(userId = userId)) }
|
||||
|
||||
override fun getTwoFactorToken(email: String): String? =
|
||||
getString(key = TWO_FACTOR_TOKEN_KEY.appendIdentifier(email))
|
||||
|
||||
@@ -579,6 +621,12 @@ class AuthDiskSourceImpl(
|
||||
bufferedMutableSharedFlow(replay = 1)
|
||||
}
|
||||
|
||||
private fun getMutablePinProtectedUserKeyEnvelopeFlow(
|
||||
userId: String,
|
||||
): MutableSharedFlow<String?> = mutablePinProtectedUserKeyEnvelopeFlowMap.getOrPut(userId) {
|
||||
bufferedMutableSharedFlow(replay = 1)
|
||||
}
|
||||
|
||||
private fun migrateAccountTokens() {
|
||||
userState
|
||||
?.accounts
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.x8bit.bitwarden.data.auth.manager
|
||||
|
||||
import com.x8bit.bitwarden.ui.vault.model.TotpData
|
||||
import com.bitwarden.ui.platform.model.TotpData
|
||||
|
||||
/**
|
||||
* Manager for keeping track of requests from the Bitwarden Authenticator app to add a TOTP
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.x8bit.bitwarden.data.auth.manager
|
||||
|
||||
import com.x8bit.bitwarden.ui.vault.model.TotpData
|
||||
import com.bitwarden.ui.platform.model.TotpData
|
||||
|
||||
/**
|
||||
* Default in memory implementation for [AddTotpItemFromAuthenticatorManager].
|
||||
|
||||
@@ -8,8 +8,8 @@ import androidx.core.app.NotificationChannelCompat
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import com.bitwarden.annotation.OmitFromCoverage
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.util.toPendingIntentMutabilityFlag
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.ui.platform.resource.BitwardenDrawable
|
||||
import com.bitwarden.ui.platform.resource.BitwardenString
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
||||
|
||||
@@ -16,7 +16,7 @@ import com.x8bit.bitwarden.data.auth.repository.util.toUserStateJsonKdfUpdatedMi
|
||||
import com.x8bit.bitwarden.data.auth.util.KdfParamsConstants.DEFAULT_PBKDF2_ITERATIONS
|
||||
import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.VaultSdkSource
|
||||
import kotlin.collections.get
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Default implementation of [KdfManager].
|
||||
@@ -71,6 +71,7 @@ class KdfManagerImpl(
|
||||
onSuccess = {
|
||||
authDiskSource.userState = authDiskSource.userState
|
||||
?.toUserStateJsonKdfUpdatedMinimums()
|
||||
Timber.d("[Auth] Upgraded user's KDF to minimums")
|
||||
UpdateKdfMinimumsResult.Success
|
||||
},
|
||||
onFailure = { UpdateKdfMinimumsResult.Error(error = it) },
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.x8bit.bitwarden.data.auth.manager
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.toast.ToastManager
|
||||
import com.bitwarden.core.data.repository.util.bufferedMutableSharedFlow
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.ui.platform.resource.BitwardenString
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
||||
import com.x8bit.bitwarden.data.auth.manager.model.LogoutEvent
|
||||
@@ -77,15 +77,10 @@ class UserLogoutManagerImpl(
|
||||
if (isExpired) {
|
||||
showToast(message = BitwardenString.login_expired)
|
||||
}
|
||||
authDiskSource.storeAccountTokens(
|
||||
userId = userId,
|
||||
accountTokens = null,
|
||||
)
|
||||
|
||||
// Save any data that will still need to be retained after otherwise clearing all dat
|
||||
val vaultTimeoutInMinutes = settingsDiskSource.getVaultTimeoutInMinutes(userId = userId)
|
||||
val vaultTimeoutAction = settingsDiskSource.getVaultTimeoutAction(userId = userId)
|
||||
val pinProtectedUserKey = authDiskSource.getPinProtectedUserKey(userId = userId)
|
||||
|
||||
switchUserIfAvailable(
|
||||
currentUserId = userId,
|
||||
@@ -107,10 +102,6 @@ class UserLogoutManagerImpl(
|
||||
vaultTimeoutAction = vaultTimeoutAction,
|
||||
)
|
||||
}
|
||||
authDiskSource.storePinProtectedUserKey(
|
||||
userId = userId,
|
||||
pinProtectedUserKey = pinProtectedUserKey,
|
||||
)
|
||||
}
|
||||
|
||||
private fun clearData(userId: String) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.x8bit.bitwarden.data.auth.manager
|
||||
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.network.model.PolicyTypeJson
|
||||
import com.bitwarden.network.model.SyncResponseJson
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.model.OnboardingStatus
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.model.UserStateJson
|
||||
@@ -19,6 +21,7 @@ import com.x8bit.bitwarden.data.auth.repository.util.userKeyConnectorStateList
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.userOrganizationsList
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.userOrganizationsListFlow
|
||||
import com.x8bit.bitwarden.data.platform.manager.FirstTimeActionManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.PolicyManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.model.FirstTimeState
|
||||
import com.x8bit.bitwarden.data.vault.manager.VaultLockManager
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultUnlockData
|
||||
@@ -39,6 +42,7 @@ class UserStateManagerImpl(
|
||||
private val authDiskSource: AuthDiskSource,
|
||||
firstTimeActionManager: FirstTimeActionManager,
|
||||
vaultLockManager: VaultLockManager,
|
||||
private val policyManager: PolicyManager,
|
||||
dispatcherManager: DispatcherManager,
|
||||
) : UserStateManager {
|
||||
private val unconfinedScope = CoroutineScope(dispatcherManager.unconfined)
|
||||
@@ -110,6 +114,7 @@ class UserStateManagerImpl(
|
||||
vaultUnlockTypeProvider = ::getVaultUnlockType,
|
||||
isDeviceTrustedProvider = ::isDeviceTrusted,
|
||||
firstTimeState = firstTimeState,
|
||||
getUserPolicies = ::existingPolicies,
|
||||
)
|
||||
}
|
||||
.filterNot {
|
||||
@@ -133,6 +138,7 @@ class UserStateManagerImpl(
|
||||
vaultUnlockTypeProvider = ::getVaultUnlockType,
|
||||
isDeviceTrustedProvider = ::isDeviceTrusted,
|
||||
firstTimeState = firstTimeActionManager.currentOrDefaultUserFirstTimeState,
|
||||
getUserPolicies = ::existingPolicies,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -156,7 +162,15 @@ class UserStateManagerImpl(
|
||||
private fun getVaultUnlockType(
|
||||
userId: String,
|
||||
): VaultUnlockType = authDiskSource
|
||||
.getPinProtectedUserKey(userId = userId)
|
||||
.getPinProtectedUserKeyEnvelope(userId = userId)
|
||||
?.let { VaultUnlockType.PIN }
|
||||
?: VaultUnlockType.MASTER_PASSWORD
|
||||
|
||||
private fun existingPolicies(
|
||||
userId: String,
|
||||
policyType: PolicyTypeJson,
|
||||
): List<SyncResponseJson.Policy> = policyManager.getUserPolicies(
|
||||
userId = userId,
|
||||
type = policyType,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.x8bit.bitwarden.data.auth.manager.di
|
||||
|
||||
import android.content.Context
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.toast.ToastManager
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.network.service.AccountsService
|
||||
import com.bitwarden.network.service.AuthRequestsService
|
||||
import com.bitwarden.network.service.DevicesService
|
||||
@@ -27,8 +27,8 @@ import com.x8bit.bitwarden.data.auth.manager.UserLogoutManager
|
||||
import com.x8bit.bitwarden.data.auth.manager.UserLogoutManagerImpl
|
||||
import com.x8bit.bitwarden.data.platform.datasource.disk.PushDiskSource
|
||||
import com.x8bit.bitwarden.data.platform.datasource.disk.SettingsDiskSource
|
||||
import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.CredentialExchangeRegistryManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.PushManager
|
||||
import com.x8bit.bitwarden.data.tools.generator.datasource.disk.GeneratorDiskSource
|
||||
import com.x8bit.bitwarden.data.tools.generator.datasource.disk.PasswordHistoryDiskSource
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.x8bit.bitwarden.data.auth.repository
|
||||
|
||||
import com.bitwarden.core.AuthRequestMethod
|
||||
import com.bitwarden.core.InitUserCryptoMethod
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.data.repository.util.bufferedMutableSharedFlow
|
||||
import com.bitwarden.core.data.util.asFailure
|
||||
import com.bitwarden.core.data.util.asSuccess
|
||||
@@ -9,7 +10,6 @@ import com.bitwarden.core.data.util.flatMap
|
||||
import com.bitwarden.crypto.HashPurpose
|
||||
import com.bitwarden.crypto.Kdf
|
||||
import com.bitwarden.data.datasource.disk.ConfigDiskSource
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.data.repository.util.toEnvironmentUrls
|
||||
import com.bitwarden.data.repository.util.toEnvironmentUrlsOrDefault
|
||||
import com.bitwarden.network.model.DeleteAccountResponseJson
|
||||
@@ -51,7 +51,6 @@ import com.x8bit.bitwarden.data.auth.datasource.disk.model.OnboardingStatus
|
||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.DeviceDataModel
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.AuthSdkSource
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.util.toInt
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.util.toKdf
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.util.toKdfTypeJson
|
||||
import com.x8bit.bitwarden.data.auth.manager.AuthRequestManager
|
||||
import com.x8bit.bitwarden.data.auth.manager.KdfManager
|
||||
@@ -113,6 +112,7 @@ import com.x8bit.bitwarden.data.vault.datasource.sdk.VaultSdkSource
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultUnlockError
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultUnlockResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.util.toSdkMasterPasswordUnlock
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
@@ -1023,12 +1023,6 @@ class AuthRepositoryImpl(
|
||||
}
|
||||
.fold(
|
||||
onSuccess = {
|
||||
// Clear the password reset reason, since it's no longer relevant.
|
||||
storeUserResetPasswordReason(
|
||||
userId = activeAccount.profile.userId,
|
||||
reason = null,
|
||||
)
|
||||
|
||||
// Update the saved master password hash.
|
||||
authSdkSource
|
||||
.hashPassword(
|
||||
@@ -1044,6 +1038,10 @@ class AuthRepositoryImpl(
|
||||
)
|
||||
}
|
||||
|
||||
// Log out the user after successful password reset.
|
||||
// This clears all user state including forcePasswordResetReason.
|
||||
logout(reason = LogoutReason.PasswordReset)
|
||||
|
||||
// Return the success.
|
||||
ResetPasswordResult.Success
|
||||
},
|
||||
@@ -1295,8 +1293,8 @@ class AuthRepositoryImpl(
|
||||
?.activeAccount
|
||||
?.profile
|
||||
?: return ValidatePinResult.Error(error = NoActiveUserException())
|
||||
val pinProtectedUserKey = authDiskSource
|
||||
.getPinProtectedUserKey(userId = activeAccount.userId)
|
||||
val pinProtectedUserKeyEnvelope = authDiskSource
|
||||
.getPinProtectedUserKeyEnvelope(userId = activeAccount.userId)
|
||||
?: return ValidatePinResult.Error(
|
||||
error = MissingPropertyException("Pin Protected User Key"),
|
||||
)
|
||||
@@ -1304,7 +1302,7 @@ class AuthRepositoryImpl(
|
||||
.validatePin(
|
||||
userId = activeAccount.userId,
|
||||
pin = pin,
|
||||
pinProtectedUserKey = pinProtectedUserKey,
|
||||
pinProtectedUserKey = pinProtectedUserKeyEnvelope,
|
||||
)
|
||||
.fold(
|
||||
onSuccess = { ValidatePinResult.Success(isValid = it) },
|
||||
@@ -1886,15 +1884,27 @@ class AuthRepositoryImpl(
|
||||
val masterPassword = password ?: return null
|
||||
val privateKey = loginResponse.privateKeyOrNull() ?: return null
|
||||
val key = loginResponse.key ?: return null
|
||||
|
||||
val initUserCryptoMethod = loginResponse
|
||||
.userDecryptionOptions
|
||||
?.masterPasswordUnlock
|
||||
?.let { masterPasswordUnlock ->
|
||||
InitUserCryptoMethod.MasterPasswordUnlock(
|
||||
password = masterPassword,
|
||||
masterPasswordUnlock = masterPasswordUnlock.toSdkMasterPasswordUnlock(),
|
||||
)
|
||||
}
|
||||
?: InitUserCryptoMethod.Password(
|
||||
password = masterPassword,
|
||||
userKey = key,
|
||||
)
|
||||
|
||||
return unlockVault(
|
||||
accountProfile = profile,
|
||||
privateKey = privateKey,
|
||||
securityState = loginResponse.accountKeys?.securityState?.securityState,
|
||||
signingKey = loginResponse.accountKeys?.signatureKeyPair?.wrappedSigningKey,
|
||||
initUserCryptoMethod = InitUserCryptoMethod.Password(
|
||||
password = masterPassword,
|
||||
userKey = key,
|
||||
),
|
||||
initUserCryptoMethod = initUserCryptoMethod,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2047,20 +2057,10 @@ class AuthRepositoryImpl(
|
||||
initUserCryptoMethod: InitUserCryptoMethod,
|
||||
): VaultUnlockResult {
|
||||
val userId = accountProfile.userId
|
||||
val kdfParams = (initUserCryptoMethod as? InitUserCryptoMethod.Password)
|
||||
?.let {
|
||||
accountProfile
|
||||
.userDecryptionOptions
|
||||
?.masterPasswordUnlock
|
||||
?.kdf
|
||||
?.toKdf()
|
||||
}
|
||||
?: accountProfile.toSdkParams()
|
||||
|
||||
return vaultRepository.unlockVault(
|
||||
userId = userId,
|
||||
email = accountProfile.email,
|
||||
kdf = kdfParams,
|
||||
kdf = accountProfile.toSdkParams(),
|
||||
privateKey = privateKey,
|
||||
signingKey = signingKey,
|
||||
securityState = securityState,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.x8bit.bitwarden.data.auth.repository.di
|
||||
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.data.datasource.disk.ConfigDiskSource
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.network.service.AccountsService
|
||||
import com.bitwarden.network.service.DevicesService
|
||||
import com.bitwarden.network.service.HaveIBeenPwnedService
|
||||
@@ -102,11 +102,13 @@ object AuthRepositoryModule {
|
||||
authDiskSource: AuthDiskSource,
|
||||
firstTimeActionManager: FirstTimeActionManager,
|
||||
vaultLockManager: VaultLockManager,
|
||||
policyManager: PolicyManager,
|
||||
dispatcherManager: DispatcherManager,
|
||||
): UserStateManager = UserStateManagerImpl(
|
||||
authDiskSource = authDiskSource,
|
||||
firstTimeActionManager = firstTimeActionManager,
|
||||
vaultLockManager = vaultLockManager,
|
||||
policyManager = policyManager,
|
||||
dispatcherManager = dispatcherManager,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -66,6 +66,11 @@ sealed class LogoutReason {
|
||||
*/
|
||||
data object Notification : LogoutReason()
|
||||
|
||||
/**
|
||||
* Indicates that the logout is happening because the user reset their master password.
|
||||
*/
|
||||
data object PasswordReset : LogoutReason()
|
||||
|
||||
/**
|
||||
* Indicates that the logout is happening because the sync security stamp was invalidated.
|
||||
*/
|
||||
|
||||
@@ -122,6 +122,42 @@ sealed class PolicyInformation {
|
||||
val minutes: Int?,
|
||||
|
||||
@SerialName("action")
|
||||
val action: String?,
|
||||
) : PolicyInformation()
|
||||
val action: Action?,
|
||||
|
||||
@SerialName("type")
|
||||
val type: Type?,
|
||||
) : PolicyInformation() {
|
||||
/**
|
||||
* The action to take when the vault timeout is reached.
|
||||
*/
|
||||
@Serializable
|
||||
enum class Action {
|
||||
@SerialName("lock")
|
||||
LOCK,
|
||||
|
||||
@SerialName("logOut")
|
||||
LOGOUT,
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of vault timeout.
|
||||
*/
|
||||
@Serializable
|
||||
enum class Type {
|
||||
@SerialName("never")
|
||||
NEVER,
|
||||
|
||||
@SerialName("onAppRestart")
|
||||
ON_APP_RESTART,
|
||||
|
||||
@SerialName("onSystemLock")
|
||||
ON_SYSTEM_LOCK,
|
||||
|
||||
@SerialName("immediately")
|
||||
IMMEDIATELY,
|
||||
|
||||
@SerialName("custom")
|
||||
CUSTOM,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ data class UserState(
|
||||
val isUsingKeyConnector: Boolean,
|
||||
val onboardingStatus: OnboardingStatus,
|
||||
val firstTimeState: FirstTimeState,
|
||||
val isExportable: Boolean,
|
||||
) {
|
||||
/**
|
||||
* Indicates that the user does or does not have a means to manually unlock the vault.
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.x8bit.bitwarden.data.auth.repository.util
|
||||
import com.bitwarden.data.repository.util.toEnvironmentUrlsOrDefault
|
||||
import com.bitwarden.network.model.KdfTypeJson
|
||||
import com.bitwarden.network.model.OrganizationType
|
||||
import com.bitwarden.network.model.PolicyTypeJson
|
||||
import com.bitwarden.network.model.SyncResponseJson
|
||||
import com.bitwarden.network.model.UserDecryptionOptionsJson
|
||||
import com.bitwarden.ui.platform.base.util.toHexColorRepresentation
|
||||
@@ -164,6 +165,7 @@ fun UserStateJson.toUserState(
|
||||
isBiometricsEnabledProvider: (userId: String) -> Boolean,
|
||||
vaultUnlockTypeProvider: (userId: String) -> VaultUnlockType,
|
||||
isDeviceTrustedProvider: (userId: String) -> Boolean,
|
||||
getUserPolicies: (userId: String, policy: PolicyTypeJson) -> List<SyncResponseJson.Policy>,
|
||||
): UserState =
|
||||
UserState(
|
||||
activeUserId = this.activeUserId,
|
||||
@@ -203,6 +205,19 @@ fun UserStateJson.toUserState(
|
||||
hasManageResetPasswordPermission.takeIf { trustedDevice != null }
|
||||
val needsMasterPassword = decryptionOptions?.hasMasterPassword == false &&
|
||||
(tdeUserNeedsMasterPassword ?: (keyConnectorOptions == null))
|
||||
|
||||
val hasPersonalOwnershipRestrictedOrg = getUserPolicies(
|
||||
userId,
|
||||
PolicyTypeJson.PERSONAL_OWNERSHIP,
|
||||
)
|
||||
.any { it.isEnabled }
|
||||
|
||||
val hasPersonalVaultExportRestrictedOrg = getUserPolicies(
|
||||
userId,
|
||||
PolicyTypeJson.DISABLE_PERSONAL_VAULT_EXPORT,
|
||||
)
|
||||
.any { it.isEnabled }
|
||||
|
||||
UserState.Account(
|
||||
userId = userId,
|
||||
name = profile.name,
|
||||
@@ -231,6 +246,8 @@ fun UserStateJson.toUserState(
|
||||
// using the app prior to the release of the onboarding flow.
|
||||
onboardingStatus = onboardingStatus ?: OnboardingStatus.COMPLETE,
|
||||
firstTimeState = firstTimeState,
|
||||
isExportable = !hasPersonalOwnershipRestrictedOrg &&
|
||||
!hasPersonalVaultExportRestrictedOrg,
|
||||
)
|
||||
},
|
||||
hasPendingAccountAddition = hasPendingAccountAddition,
|
||||
|
||||
@@ -4,8 +4,8 @@ import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.PowerManager
|
||||
import android.view.accessibility.AccessibilityManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.toast.ToastManager
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.autofill.accessibility.manager.AccessibilityAutofillManager
|
||||
import com.x8bit.bitwarden.data.autofill.accessibility.manager.AccessibilityAutofillManagerImpl
|
||||
import com.x8bit.bitwarden.data.autofill.accessibility.manager.AccessibilityCompletionManager
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.x8bit.bitwarden.data.autofill.accessibility.manager
|
||||
|
||||
import android.app.Activity
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.vault.CipherView
|
||||
import com.x8bit.bitwarden.data.autofill.accessibility.model.AccessibilityAction
|
||||
import com.x8bit.bitwarden.data.autofill.accessibility.util.toUriOrNull
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.x8bit.bitwarden.data.autofill.di
|
||||
|
||||
import android.content.Context
|
||||
import android.view.autofill.AutofillManager
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.autofill.builder.FillResponseBuilder
|
||||
import com.x8bit.bitwarden.data.autofill.builder.FillResponseBuilderImpl
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.x8bit.bitwarden.data.autofill.manager
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.vault.CipherView
|
||||
import com.x8bit.bitwarden.data.autofill.builder.FilledDataBuilder
|
||||
import com.x8bit.bitwarden.data.autofill.builder.FilledDataBuilderImpl
|
||||
|
||||
@@ -7,10 +7,12 @@ import android.view.autofill.AutofillId
|
||||
*
|
||||
* @param autofillViews The list of views we care about for autofilling.
|
||||
* @param idPackage The package id for this view, if there is one.
|
||||
* @param urlBarWebsites The website associated with the URL bar view.
|
||||
* @param ignoreAutofillIds The list of [AutofillId]s that should be ignored in the fill response.
|
||||
*/
|
||||
data class ViewNodeTraversalData(
|
||||
val autofillViews: List<AutofillView>,
|
||||
val idPackage: String?,
|
||||
val urlBarWebsites: List<String>,
|
||||
val ignoreAutofillIds: List<AutofillId>,
|
||||
)
|
||||
|
||||
@@ -29,6 +29,20 @@ private val BLOCK_LISTED_URIS: List<String> = listOf(
|
||||
"androidapp://com.oneplus.applocker",
|
||||
)
|
||||
|
||||
/**
|
||||
* A map of package ids and the known associated id entry for their url bar.
|
||||
*/
|
||||
private val URL_BARS: Map<String, String> = mapOf(
|
||||
"com.microsoft.emmx" to "url_bar",
|
||||
"com.microsoft.emmx.beta" to "url_bar",
|
||||
"com.microsoft.emmx.canary" to "url_bar",
|
||||
"com.microsoft.emmx.dev" to "url_bar",
|
||||
"com.sec.android.app.sbrowser" to "location_bar_edit_text",
|
||||
"com.sec.android.app.sbrowser.beta" to "location_bar_edit_text",
|
||||
"com.opera.browser" to "url_bar",
|
||||
"com.opera.browser.beta" to "url_bar",
|
||||
)
|
||||
|
||||
/**
|
||||
* The default [AutofillParser] implementation for the app. This is a tool for parsing autofill data
|
||||
* from the OS into domain models.
|
||||
@@ -76,18 +90,23 @@ class AutofillParserImpl(
|
||||
Timber.d("Parsing AssistStructure -- ${fillRequest?.id}")
|
||||
// Parse the `assistStructure` into internal models.
|
||||
val traversalDataList = assistStructure.traverse()
|
||||
val urlBarWebsite = traversalDataList
|
||||
.flatMap { it.urlBarWebsites }
|
||||
.firstOrNull()
|
||||
|
||||
// Take only the autofill views from the node that currently has focus.
|
||||
// Then remove all the fields that cannot be filled with data.
|
||||
// We fallback to taking all the fillable views if nothing has focus.
|
||||
val autofillViewsList = traversalDataList.map { it.autofillViews }
|
||||
val autofillViews = autofillViewsList
|
||||
val autofillViews = (autofillViewsList
|
||||
.filter { views -> views.any { it.data.isFocused } }
|
||||
.flatten()
|
||||
.filter { it !is AutofillView.Unused }
|
||||
.takeUnless { it.isEmpty() }
|
||||
?: autofillViewsList
|
||||
.flatten()
|
||||
.filter { it !is AutofillView.Unused }
|
||||
.filter { it !is AutofillView.Unused })
|
||||
.map { it.updateWebsiteIfNecessary(website = urlBarWebsite) }
|
||||
|
||||
// Find the focused view, or fallback to the first fillable item on the screen (so
|
||||
// we at least have something to hook into)
|
||||
@@ -254,7 +273,15 @@ private fun AssistStructure.ViewNode.traverse(
|
||||
// Set up mutable lists for collecting valid AutofillViews and ignorable view ids.
|
||||
val mutableAutofillViewList: MutableList<AutofillView> = mutableListOf()
|
||||
val mutableIgnoreAutofillIdList: MutableList<AutofillId> = mutableListOf()
|
||||
var idPackage: String? = this.idPackage
|
||||
// OS sometimes defaults node.idPackage to "android", which is not a valid
|
||||
// package name so it is ignored to prevent auto-filling unknown applications.
|
||||
var storedIdPackage: String? = this.idPackage?.takeUnless { it.isBlank() || it == "android" }
|
||||
val storedUrlBarId = storedIdPackage?.let { URL_BARS[it] }
|
||||
val storedUrlBarWebsites: MutableList<String> = this
|
||||
.website
|
||||
?.takeIf { _ -> storedUrlBarId != null && storedUrlBarId == this.idEntry }
|
||||
?.let { mutableListOf(it) }
|
||||
?: mutableListOf()
|
||||
|
||||
// Try converting this `ViewNode` into an `AutofillView`. If a valid instance is returned, add
|
||||
// it to the list. Otherwise, ignore the `AutofillId` associated with this `ViewNode`.
|
||||
@@ -272,13 +299,12 @@ private fun AssistStructure.ViewNode.traverse(
|
||||
viewNodeTraversalData.ignoreAutofillIds.forEach(mutableIgnoreAutofillIdList::add)
|
||||
|
||||
// Get the first non-null idPackage.
|
||||
if (idPackage.isNullOrBlank() &&
|
||||
// OS sometimes defaults node.idPackage to "android", which is not a valid
|
||||
// package name so it is ignored to prevent auto-filling unknown applications.
|
||||
viewNodeTraversalData.idPackage?.equals("android") == false
|
||||
) {
|
||||
idPackage = viewNodeTraversalData.idPackage
|
||||
if (storedIdPackage == null) {
|
||||
storedIdPackage = viewNodeTraversalData.idPackage
|
||||
}
|
||||
// Add all url bar websites. We will deal with this later if
|
||||
// there is somehow more than one.
|
||||
storedUrlBarWebsites.addAll(viewNodeTraversalData.urlBarWebsites)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +312,29 @@ private fun AssistStructure.ViewNode.traverse(
|
||||
// descendant's.
|
||||
return ViewNodeTraversalData(
|
||||
autofillViews = mutableAutofillViewList,
|
||||
idPackage = idPackage,
|
||||
idPackage = storedIdPackage,
|
||||
urlBarWebsites = storedUrlBarWebsites,
|
||||
ignoreAutofillIds = mutableIgnoreAutofillIdList,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* This updates the underlying [AutofillView.data] with the given [website] if it does not already
|
||||
* have a website associated with it.
|
||||
*/
|
||||
private fun AutofillView.updateWebsiteIfNecessary(website: String?): AutofillView {
|
||||
val site = website ?: return this
|
||||
if (this.data.website != null) return this
|
||||
return when (this) {
|
||||
is AutofillView.Card.Brand -> this.copy(data = this.data.copy(website = site))
|
||||
is AutofillView.Card.CardholderName -> this.copy(data = this.data.copy(website = site))
|
||||
is AutofillView.Card.ExpirationDate -> this.copy(data = this.data.copy(website = site))
|
||||
is AutofillView.Card.ExpirationMonth -> this.copy(data = this.data.copy(website = site))
|
||||
is AutofillView.Card.ExpirationYear -> this.copy(data = this.data.copy(website = site))
|
||||
is AutofillView.Card.Number -> this.copy(data = this.data.copy(website = site))
|
||||
is AutofillView.Card.SecurityCode -> this.copy(data = this.data.copy(website = site))
|
||||
is AutofillView.Login.Password -> this.copy(data = this.data.copy(website = site))
|
||||
is AutofillView.Login.Username -> this.copy(data = this.data.copy(website = site))
|
||||
is AutofillView.Unused -> this.copy(data = this.data.copy(website = site))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.service.autofill.FillCallback
|
||||
import android.service.autofill.FillRequest
|
||||
import android.service.autofill.SaveCallback
|
||||
import android.service.autofill.SaveRequest
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.network.model.PolicyTypeJson
|
||||
import com.x8bit.bitwarden.data.autofill.builder.FillResponseBuilder
|
||||
import com.x8bit.bitwarden.data.autofill.builder.FilledDataBuilder
|
||||
|
||||
@@ -51,35 +51,28 @@ private val AssistStructure.ViewNode.isInputField: Boolean
|
||||
*/
|
||||
fun AssistStructure.ViewNode.toAutofillView(
|
||||
parentWebsite: String?,
|
||||
): AutofillView? =
|
||||
this
|
||||
.autofillId
|
||||
// We only care about nodes with a valid `AutofillId`.
|
||||
?.let { nonNullAutofillId ->
|
||||
if (supportedAutofillHint != null || this.isInputField) {
|
||||
val autofillOptions = this
|
||||
.autofillOptions
|
||||
.orEmpty()
|
||||
.map { it.toString() }
|
||||
|
||||
val autofillViewData = AutofillView.Data(
|
||||
autofillId = nonNullAutofillId,
|
||||
autofillOptions = autofillOptions,
|
||||
autofillType = this.autofillType,
|
||||
isFocused = this.isFocused,
|
||||
textValue = this.autofillValue?.extractTextValue(),
|
||||
hasPasswordTerms = this.hasPasswordTerms(),
|
||||
website = this.website ?: parentWebsite,
|
||||
)
|
||||
buildAutofillView(
|
||||
autofillOptions = autofillOptions,
|
||||
autofillViewData = autofillViewData,
|
||||
autofillHint = supportedAutofillHint,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
): AutofillView? {
|
||||
val nonNullAutofillId = this.autofillId ?: return null
|
||||
if (this.supportedAutofillHint == null && !this.isInputField) return null
|
||||
val autofillOptions = this
|
||||
.autofillOptions
|
||||
.orEmpty()
|
||||
.map { it.toString() }
|
||||
val autofillViewData = AutofillView.Data(
|
||||
autofillId = nonNullAutofillId,
|
||||
autofillOptions = autofillOptions,
|
||||
autofillType = this.autofillType,
|
||||
isFocused = this.isFocused,
|
||||
textValue = this.autofillValue?.extractTextValue(),
|
||||
hasPasswordTerms = this.hasPasswordTerms(),
|
||||
website = this.website ?: parentWebsite,
|
||||
)
|
||||
return buildAutofillView(
|
||||
autofillOptions = autofillOptions,
|
||||
autofillViewData = autofillViewData,
|
||||
autofillHint = this.supportedAutofillHint,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The first supported autofill hint for this view node, or null if none are found.
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.x8bit.bitwarden.data.credentials.di
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.network.service.DigitalAssetLinkService
|
||||
import com.bitwarden.sdk.Fido2CredentialStore
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
@@ -22,6 +22,8 @@ import com.x8bit.bitwarden.data.credentials.processor.CredentialProviderProcesso
|
||||
import com.x8bit.bitwarden.data.credentials.processor.CredentialProviderProcessorImpl
|
||||
import com.x8bit.bitwarden.data.credentials.repository.PrivilegedAppRepository
|
||||
import com.x8bit.bitwarden.data.credentials.repository.PrivilegedAppRepositoryImpl
|
||||
import com.x8bit.bitwarden.data.credentials.sanitizer.PasskeyAttestationOptionsSanitizer
|
||||
import com.x8bit.bitwarden.data.credentials.sanitizer.PasskeyAttestationOptionsSanitizerImpl
|
||||
import com.x8bit.bitwarden.data.platform.manager.AssetManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.BiometricsEncryptionManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.ciphermatching.CipherMatchingManager
|
||||
@@ -75,15 +77,17 @@ object CredentialProviderModule {
|
||||
dispatcherManager: DispatcherManager,
|
||||
credentialEntryBuilder: CredentialEntryBuilder,
|
||||
cipherMatchingManager: CipherMatchingManager,
|
||||
passkeyAttestationOptionsSanitizer: PasskeyAttestationOptionsSanitizer,
|
||||
): BitwardenCredentialManager =
|
||||
BitwardenCredentialManagerImpl(
|
||||
vaultSdkSource = vaultSdkSource,
|
||||
fido2CredentialStore = fido2CredentialStore,
|
||||
credentialEntryBuilder = credentialEntryBuilder,
|
||||
json = json,
|
||||
vaultRepository = vaultRepository,
|
||||
dispatcherManager = dispatcherManager,
|
||||
credentialEntryBuilder = credentialEntryBuilder,
|
||||
cipherMatchingManager = cipherMatchingManager,
|
||||
passkeyAttestationOptionsSanitizer = passkeyAttestationOptionsSanitizer,
|
||||
dispatcherManager = dispatcherManager,
|
||||
)
|
||||
|
||||
@Provides
|
||||
@@ -139,4 +143,9 @@ object CredentialProviderModule {
|
||||
CredentialManagerPendingIntentManagerImpl(
|
||||
context = context,
|
||||
)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun providePasskeyAttestationOptionsSanitizer(): PasskeyAttestationOptionsSanitizer =
|
||||
PasskeyAttestationOptionsSanitizerImpl
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ import androidx.credentials.provider.BeginGetPublicKeyCredentialOption
|
||||
import androidx.credentials.provider.CallingAppInfo
|
||||
import androidx.credentials.provider.CredentialEntry
|
||||
import androidx.credentials.provider.ProviderGetCredentialRequest
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.data.repository.model.DataState
|
||||
import com.bitwarden.core.data.repository.util.takeUntilLoaded
|
||||
import com.bitwarden.core.data.util.asFailure
|
||||
import com.bitwarden.core.data.util.asSuccess
|
||||
import com.bitwarden.core.data.util.decodeFromStringOrNull
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.fido.ClientData
|
||||
import com.bitwarden.fido.Fido2CredentialAutofillView
|
||||
import com.bitwarden.fido.Origin
|
||||
@@ -33,6 +33,7 @@ import com.x8bit.bitwarden.data.credentials.model.GetCredentialsRequest
|
||||
import com.x8bit.bitwarden.data.credentials.model.PasskeyAssertionOptions
|
||||
import com.x8bit.bitwarden.data.credentials.model.PasskeyAttestationOptions
|
||||
import com.x8bit.bitwarden.data.credentials.model.UserVerificationRequirement
|
||||
import com.x8bit.bitwarden.data.credentials.sanitizer.PasskeyAttestationOptionsSanitizer
|
||||
import com.x8bit.bitwarden.data.platform.manager.ciphermatching.CipherMatchingManager
|
||||
import com.x8bit.bitwarden.data.platform.util.getAppOrigin
|
||||
import com.x8bit.bitwarden.data.platform.util.getAppSigningSignatureFingerprint
|
||||
@@ -60,6 +61,7 @@ class BitwardenCredentialManagerImpl(
|
||||
private val json: Json,
|
||||
private val vaultRepository: VaultRepository,
|
||||
private val cipherMatchingManager: CipherMatchingManager,
|
||||
private val passkeyAttestationOptionsSanitizer: PasskeyAttestationOptionsSanitizer,
|
||||
dispatcherManager: DispatcherManager,
|
||||
) : BitwardenCredentialManager,
|
||||
Fido2CredentialStore by fido2CredentialStore {
|
||||
@@ -359,31 +361,46 @@ class BitwardenCredentialManagerImpl(
|
||||
selectedCipherView: CipherView,
|
||||
clientData: ClientData,
|
||||
callingPackageName: String,
|
||||
): Fido2RegisterCredentialResult = vaultSdkSource
|
||||
.registerFido2Credential(
|
||||
request = RegisterFido2CredentialRequest(
|
||||
userId = userId,
|
||||
origin = sdkOrigin,
|
||||
requestJson = """{"publicKey": ${createPublicKeyCredentialRequest.requestJson}}""",
|
||||
clientData = clientData,
|
||||
selectedCipherView = selectedCipherView,
|
||||
// User verification is handled prior to engaging the SDK. We always respond
|
||||
// `true` so that the SDK does not fail if the relying party requests UV.
|
||||
isUserVerificationSupported = true,
|
||||
),
|
||||
fido2CredentialStore = this,
|
||||
)
|
||||
.map {
|
||||
it.toAndroidAttestationResponse(callingPackageName = callingPackageName)
|
||||
}
|
||||
.mapCatching { json.encodeToString(it) }
|
||||
.fold(
|
||||
onSuccess = { Fido2RegisterCredentialResult.Success(it) },
|
||||
onFailure = {
|
||||
Timber.e(it, "Failed to register FIDO2 credential.")
|
||||
Fido2RegisterCredentialResult.Error.InternalError
|
||||
},
|
||||
)
|
||||
): Fido2RegisterCredentialResult {
|
||||
val requestJson =
|
||||
getPasskeyAttestationOptionsOrNull(createPublicKeyCredentialRequest.requestJson)
|
||||
?.let { passkeyAttestationOptionsSanitizer.sanitize(options = it) }
|
||||
?.runCatching { json.encodeToString(this) }
|
||||
?.fold(
|
||||
onSuccess = { it },
|
||||
onFailure = {
|
||||
Timber.e(it, "Failed to sanitize passkey attestation options.")
|
||||
null
|
||||
},
|
||||
)
|
||||
?: return Fido2RegisterCredentialResult.Error.InternalError
|
||||
|
||||
return vaultSdkSource
|
||||
.registerFido2Credential(
|
||||
request = RegisterFido2CredentialRequest(
|
||||
userId = userId,
|
||||
origin = sdkOrigin,
|
||||
requestJson = """{"publicKey": $requestJson}""",
|
||||
clientData = clientData,
|
||||
selectedCipherView = selectedCipherView,
|
||||
// User verification is handled prior to engaging the SDK. We always respond
|
||||
// `true` so that the SDK does not fail if the relying party requests UV.
|
||||
isUserVerificationSupported = true,
|
||||
),
|
||||
fido2CredentialStore = this,
|
||||
)
|
||||
.map {
|
||||
it.toAndroidAttestationResponse(callingPackageName = callingPackageName)
|
||||
}
|
||||
.mapCatching { json.encodeToString(it) }
|
||||
.fold(
|
||||
onSuccess = { Fido2RegisterCredentialResult.Success(it) },
|
||||
onFailure = {
|
||||
Timber.e(it, "Failed to register FIDO2 credential.")
|
||||
Fido2RegisterCredentialResult.Error.InternalError
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
private fun List<BeginGetPasswordOption>.toPasswordCredentialEntries(
|
||||
userId: String,
|
||||
|
||||
@@ -58,6 +58,13 @@ interface CredentialManagerPendingIntentManager {
|
||||
userId: String,
|
||||
): PendingIntent
|
||||
|
||||
/**
|
||||
* Creates a pending intent to use when providing options for Password credential creation.
|
||||
*/
|
||||
fun createPasswordCreationPendingIntent(
|
||||
userId: String,
|
||||
): PendingIntent
|
||||
|
||||
/**
|
||||
* Creates a pending intent to use when providing options for Password credential filling.
|
||||
*/
|
||||
|
||||
@@ -75,6 +75,24 @@ class CredentialManagerPendingIntentManagerImpl(
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a pending intent to use when providing options for FIDO 2 credential creation.
|
||||
*/
|
||||
override fun createPasswordCreationPendingIntent(
|
||||
userId: String,
|
||||
): PendingIntent {
|
||||
val intent = Intent(CREATE_PASSWORD_ACTION)
|
||||
.setPackage(context.packageName)
|
||||
.putExtra(EXTRA_KEY_USER_ID, userId)
|
||||
|
||||
return PendingIntent.getActivity(
|
||||
/* context = */ context,
|
||||
/* requestCode = */ Random.nextInt(),
|
||||
/* intent = */ intent,
|
||||
/* flags = */ PendingIntent.FLAG_UPDATE_CURRENT.toPendingIntentMutabilityFlag(),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a pending intent to use when providing options for Password credential filling.
|
||||
*/
|
||||
@@ -101,4 +119,5 @@ class CredentialManagerPendingIntentManagerImpl(
|
||||
private const val CREATE_PASSKEY_ACTION = "com.x8bit.bitwarden.credentials.ACTION_CREATE_PASSKEY"
|
||||
private const val UNLOCK_ACCOUNT_ACTION = "com.x8bit.bitwarden.credentials.ACTION_UNLOCK_ACCOUNT"
|
||||
private const val GET_PASSKEY_ACTION = "com.x8bit.bitwarden.credentials.ACTION_GET_PASSKEY"
|
||||
private const val CREATE_PASSWORD_ACTION = "com.x8bit.bitwarden.credentials.ACTION_CREATE_PASSWORD"
|
||||
private const val GET_PASSWORD_ACTION = "com.x8bit.bitwarden.credentials.ACTION_GET_PASSWORD"
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.x8bit.bitwarden.data.credentials.manager
|
||||
import androidx.credentials.provider.CallingAppInfo
|
||||
import com.bitwarden.network.service.DigitalAssetLinkService
|
||||
import com.bitwarden.ui.platform.base.util.prefixHttpsIfNecessary
|
||||
import com.bitwarden.ui.platform.base.util.prefixWwwIfNecessary
|
||||
import com.x8bit.bitwarden.data.credentials.model.ValidateOriginResult
|
||||
import com.x8bit.bitwarden.data.credentials.repository.PrivilegedAppRepository
|
||||
import com.x8bit.bitwarden.data.platform.manager.AssetManager
|
||||
@@ -40,7 +41,13 @@ class OriginManagerImpl(
|
||||
): ValidateOriginResult {
|
||||
return digitalAssetLinkService
|
||||
.checkDigitalAssetLinksRelations(
|
||||
sourceWebSite = relyingPartyId.prefixHttpsIfNecessary(),
|
||||
sourceWebSite = relyingPartyId
|
||||
// The DAL API does not allow redirects, so we add `www.` to prevent redirects
|
||||
// when it is absent from the `relyingPartyId`. This ensures that relying
|
||||
// parties storing their `assetlinks.json` at the `www.` subdomain do not fail
|
||||
// verification checks.
|
||||
.prefixWwwIfNecessary()
|
||||
.prefixHttpsIfNecessary(),
|
||||
targetPackageName = callingAppInfo.packageName,
|
||||
targetCertificateFingerprint = callingAppInfo
|
||||
.getSignatureFingerprintAsHexString()
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.x8bit.bitwarden.data.credentials.model
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import androidx.credentials.CreatePasswordRequest
|
||||
import androidx.credentials.CreatePublicKeyCredentialRequest
|
||||
import androidx.credentials.provider.CallingAppInfo
|
||||
import androidx.credentials.provider.ProviderCreateCredentialRequest
|
||||
@@ -48,6 +49,15 @@ data class CreateCredentialRequest(
|
||||
providerRequest.callingRequest as? CreatePublicKeyCredentialRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* The [CreatePasswordRequest] of the [providerRequest], or null if the calling
|
||||
* request is not a [CreatePasswordRequest].
|
||||
*/
|
||||
@IgnoredOnParcel
|
||||
val createPasswordCredentialRequest: CreatePasswordRequest? by lazy {
|
||||
providerRequest.callingRequest as? CreatePasswordRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* The [requestJson] of the [createPublicKeyCredentialRequest], or null if the calling request
|
||||
* is not a [CreatePublicKeyCredentialRequest].
|
||||
|
||||
@@ -19,14 +19,15 @@ import androidx.credentials.exceptions.GetCredentialUnknownException
|
||||
import androidx.credentials.provider.AuthenticationAction
|
||||
import androidx.credentials.provider.BeginCreateCredentialRequest
|
||||
import androidx.credentials.provider.BeginCreateCredentialResponse
|
||||
import androidx.credentials.provider.BeginCreatePasswordCredentialRequest
|
||||
import androidx.credentials.provider.BeginCreatePublicKeyCredentialRequest
|
||||
import androidx.credentials.provider.BeginGetCredentialRequest
|
||||
import androidx.credentials.provider.BeginGetCredentialResponse
|
||||
import androidx.credentials.provider.BiometricPromptData
|
||||
import androidx.credentials.provider.CreateEntry
|
||||
import androidx.credentials.provider.ProviderClearCredentialStateRequest
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.util.isBuildVersionAtLeast
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.ui.platform.resource.BitwardenString
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.UserState
|
||||
@@ -69,7 +70,7 @@ class CredentialProviderProcessorImpl(
|
||||
}
|
||||
|
||||
val createCredentialJob = ioScope.launch {
|
||||
processCreateCredentialRequest(request = request)
|
||||
(handleCreatePasskeyQuery(request) ?: handleCreatePasswordQuery(request))
|
||||
?.let { callback.onResult(it) }
|
||||
?: callback.onError(CreateCredentialUnknownException())
|
||||
}
|
||||
@@ -137,21 +138,11 @@ class CredentialProviderProcessorImpl(
|
||||
callback.onError(ClearCredentialUnsupportedException())
|
||||
}
|
||||
|
||||
private fun processCreateCredentialRequest(
|
||||
private fun handleCreatePasskeyQuery(
|
||||
request: BeginCreateCredentialRequest,
|
||||
): BeginCreateCredentialResponse? {
|
||||
return when (request) {
|
||||
is BeginCreatePublicKeyCredentialRequest -> {
|
||||
handleCreatePasskeyQuery(request)
|
||||
}
|
||||
if (request !is BeginCreatePublicKeyCredentialRequest) return null
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleCreatePasskeyQuery(
|
||||
request: BeginCreatePublicKeyCredentialRequest,
|
||||
): BeginCreateCredentialResponse? {
|
||||
val requestJson = request
|
||||
.candidateQueryData
|
||||
.getString("androidx.credentials.BUNDLE_KEY_REQUEST_JSON")
|
||||
@@ -161,14 +152,19 @@ class CredentialProviderProcessorImpl(
|
||||
val userState = authRepository.userStateFlow.value ?: return null
|
||||
|
||||
return BeginCreateCredentialResponse.Builder()
|
||||
.setCreateEntries(userState.accounts.toCreateEntries(userState.activeUserId))
|
||||
.setCreateEntries(
|
||||
userState.accounts.toCreatePasskeyEntry(userState.activeUserId),
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun List<UserState.Account>.toCreateEntries(activeUserId: String) =
|
||||
map { it.toCreateEntry(isActive = activeUserId == it.userId) }
|
||||
private fun List<UserState.Account>.toCreatePasskeyEntry(
|
||||
activeUserId: String,
|
||||
): List<CreateEntry> = map { it.toCreatePasskeyEntry(isActive = activeUserId == it.userId) }
|
||||
|
||||
private fun UserState.Account.toCreateEntry(isActive: Boolean): CreateEntry {
|
||||
private fun UserState.Account.toCreatePasskeyEntry(
|
||||
isActive: Boolean,
|
||||
): CreateEntry {
|
||||
val accountName = name ?: email
|
||||
val entryBuilder = CreateEntry
|
||||
.Builder(
|
||||
@@ -196,6 +192,54 @@ class CredentialProviderProcessorImpl(
|
||||
return entryBuilder.build()
|
||||
}
|
||||
|
||||
private fun handleCreatePasswordQuery(
|
||||
request: BeginCreateCredentialRequest,
|
||||
): BeginCreateCredentialResponse? {
|
||||
if (request !is BeginCreatePasswordCredentialRequest) return null
|
||||
|
||||
val userState = authRepository.userStateFlow.value ?: return null
|
||||
|
||||
return BeginCreateCredentialResponse.Builder()
|
||||
.setCreateEntries(
|
||||
userState.accounts.toCreatePasswordEntry(userState.activeUserId),
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun List<UserState.Account>.toCreatePasswordEntry(
|
||||
activeUserId: String,
|
||||
) = map { it.toCreatePasswordEntry(isActive = activeUserId == it.userId) }
|
||||
|
||||
private fun UserState.Account.toCreatePasswordEntry(
|
||||
isActive: Boolean,
|
||||
): CreateEntry {
|
||||
val accountName = name ?: email
|
||||
val entryBuilder = CreateEntry
|
||||
.Builder(
|
||||
accountName = accountName,
|
||||
pendingIntent = pendingIntentManager.createPasswordCreationPendingIntent(
|
||||
userId = userId,
|
||||
),
|
||||
)
|
||||
.setDescription(
|
||||
context.getString(
|
||||
BitwardenString.your_password_will_be_saved_to_your_bitwarden_vault_for_x,
|
||||
accountName,
|
||||
),
|
||||
)
|
||||
// Set the last used time to "now" so the active account is the default option in the
|
||||
// system prompt.
|
||||
.setLastUsedTime(if (isActive) clock.instant() else null)
|
||||
.setAutoSelectAllowed(true)
|
||||
|
||||
if (isVaultUnlocked) {
|
||||
biometricsEncryptionManager
|
||||
.getOrCreateCipher(userId)
|
||||
?.let { entryBuilder.setBiometricPromptDataIfSupported(cipher = it) }
|
||||
}
|
||||
return entryBuilder.build()
|
||||
}
|
||||
|
||||
private fun CreateEntry.Builder.setBiometricPromptDataIfSupported(
|
||||
cipher: Cipher,
|
||||
): CreateEntry.Builder {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.x8bit.bitwarden.data.credentials.repository
|
||||
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.data.repository.model.DataState
|
||||
import com.bitwarden.core.data.repository.util.combineDataStates
|
||||
import com.bitwarden.core.data.util.decodeFromStringOrNull
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.credentials.datasource.disk.PrivilegedAppDiskSource
|
||||
import com.x8bit.bitwarden.data.credentials.datasource.disk.entity.PrivilegedAppEntity
|
||||
import com.x8bit.bitwarden.data.credentials.model.PrivilegedAppAllowListJson
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.x8bit.bitwarden.data.credentials.sanitizer
|
||||
|
||||
import com.x8bit.bitwarden.data.credentials.model.PasskeyAttestationOptions
|
||||
|
||||
/**
|
||||
* Defines a contract for sanitizing [PasskeyAttestationOptions] received from applications.
|
||||
*
|
||||
* Sanitization applies workarounds for known issues with specific applications'
|
||||
* passkey implementations, ensuring the options are in the correct format before
|
||||
* being used to create a passkey credential.
|
||||
*/
|
||||
interface PasskeyAttestationOptionsSanitizer {
|
||||
|
||||
/**
|
||||
* Sanitizes the given [PasskeyAttestationOptions] in preparation for use in the
|
||||
* passkey creation process.
|
||||
*
|
||||
* @param options The [PasskeyAttestationOptions] to sanitize.
|
||||
* @return A new, sanitized instance of [PasskeyAttestationOptions].
|
||||
*/
|
||||
fun sanitize(options: PasskeyAttestationOptions): PasskeyAttestationOptions
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.x8bit.bitwarden.data.credentials.sanitizer
|
||||
|
||||
import com.x8bit.bitwarden.data.credentials.model.PasskeyAttestationOptions
|
||||
|
||||
/**
|
||||
* Default implementation of [PasskeyAttestationOptionsSanitizer].
|
||||
*/
|
||||
object PasskeyAttestationOptionsSanitizerImpl : PasskeyAttestationOptionsSanitizer {
|
||||
override fun sanitize(options: PasskeyAttestationOptions): PasskeyAttestationOptions {
|
||||
// The AliExpress Android app (com.alibaba.aliexpresshd) incorrectly appends a newline
|
||||
// to the user.id field when creating a passkey. This causes the operation to fail
|
||||
// downstream. As a workaround, we detect this specific scenario, trim the newline, and
|
||||
// re-serialize the JSON request.
|
||||
return if (options.relyingParty.id == ALIEXPRESS_RP_ID &&
|
||||
options.user.id.endsWith("\n")
|
||||
) {
|
||||
options.copy(
|
||||
user = options.user.copy(id = options.user.id.trimEnd('\n')),
|
||||
)
|
||||
} else {
|
||||
options
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const val ALIEXPRESS_RP_ID = "m.aliexpress.com"
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.x8bit.bitwarden.data.platform.datasource.disk
|
||||
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.network.model.OrganizationEventJson
|
||||
import com.bitwarden.network.model.OrganizationEventType
|
||||
import com.x8bit.bitwarden.data.platform.datasource.disk.dao.OrganizationEventDao
|
||||
|
||||
@@ -4,9 +4,9 @@ import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.room.Room
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.data.datasource.disk.di.EncryptedPreferences
|
||||
import com.bitwarden.data.datasource.disk.di.UnencryptedPreferences
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.platform.datasource.disk.EnvironmentDiskSource
|
||||
import com.x8bit.bitwarden.data.platform.datasource.disk.EnvironmentDiskSourceImpl
|
||||
import com.x8bit.bitwarden.data.platform.datasource.disk.EventDiskSource
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.x8bit.bitwarden.data.platform.manager
|
||||
|
||||
import android.content.Context
|
||||
import com.bitwarden.annotation.OmitFromCoverage
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,7 @@ class CredentialExchangeRegistryManagerImpl(
|
||||
CredentialTypes.CREDENTIAL_TYPE_TOTP,
|
||||
CredentialTypes.CREDENTIAL_TYPE_WIFI,
|
||||
),
|
||||
iconResId = BitwardenDrawable.icon,
|
||||
iconResId = BitwardenDrawable.logo_bitwarden_icon,
|
||||
),
|
||||
)
|
||||
.fold(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.x8bit.bitwarden.data.platform.manager
|
||||
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.activeUserIdChangesFlow
|
||||
import com.x8bit.bitwarden.data.autofill.manager.AutofillEnabledManager
|
||||
|
||||
@@ -17,4 +17,12 @@ interface PolicyManager {
|
||||
* Get all the policies of the given [type] that are enabled and applicable to the user.
|
||||
*/
|
||||
fun getActivePolicies(type: PolicyTypeJson): List<SyncResponseJson.Policy>
|
||||
|
||||
/**
|
||||
* Get all the policies of the given [type] that are enabled and applicable to the [userId].
|
||||
*/
|
||||
fun getUserPolicies(
|
||||
userId: String,
|
||||
type: PolicyTypeJson,
|
||||
): List<SyncResponseJson.Policy>
|
||||
}
|
||||
|
||||
@@ -54,6 +54,18 @@ class PolicyManagerImpl(
|
||||
}
|
||||
?: emptyList()
|
||||
|
||||
override fun getUserPolicies(
|
||||
userId: String,
|
||||
type: PolicyTypeJson,
|
||||
): List<SyncResponseJson.Policy> =
|
||||
this
|
||||
.filterPolicies(
|
||||
userId = userId,
|
||||
type = type,
|
||||
policies = authDiskSource.getPolicies(userId = userId),
|
||||
)
|
||||
.orEmpty()
|
||||
|
||||
/**
|
||||
* A helper method to filter policies.
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.x8bit.bitwarden.data.platform.manager
|
||||
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.model.FlagKey
|
||||
import com.bitwarden.core.data.repository.util.bufferedMutableSharedFlow
|
||||
import com.bitwarden.core.data.util.decodeFromStringOrNull
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.network.model.PushTokenRequest
|
||||
import com.bitwarden.network.service.PushService
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.x8bit.bitwarden.data.platform.manager
|
||||
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.platform.manager.model.SpecialCircumstance
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.x8bit.bitwarden.data.platform.manager.di
|
||||
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.x8bit.bitwarden.MainActivity
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.platform.manager.SpecialCircumstanceManager
|
||||
|
||||
@@ -3,14 +3,14 @@ package com.x8bit.bitwarden.data.platform.manager.di
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.core.content.getSystemService
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManagerImpl
|
||||
import com.bitwarden.core.data.manager.realtime.RealtimeManager
|
||||
import com.bitwarden.core.data.manager.realtime.RealtimeManagerImpl
|
||||
import com.bitwarden.core.data.manager.toast.ToastManager
|
||||
import com.bitwarden.core.data.manager.toast.ToastManagerImpl
|
||||
import com.bitwarden.cxf.registry.CredentialExchangeRegistry
|
||||
import com.bitwarden.cxf.registry.dsl.credentialExchangeRegistry
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.data.manager.DispatcherManagerImpl
|
||||
import com.bitwarden.data.manager.NativeLibraryManager
|
||||
import com.bitwarden.data.repository.ServerConfigRepository
|
||||
import com.bitwarden.network.BitwardenServiceClient
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.x8bit.bitwarden.data.platform.manager.event
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.network.model.OrganizationEventJson
|
||||
import com.bitwarden.network.service.EventService
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
|
||||
@@ -4,9 +4,9 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.data.util.concurrentMapOf
|
||||
import com.bitwarden.core.data.util.toFormattedPattern
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.platform.datasource.disk.SettingsDiskSource
|
||||
import com.x8bit.bitwarden.data.platform.datasource.disk.model.FlightRecorderDataSet
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.FlightRecorderDuration
|
||||
|
||||
@@ -3,8 +3,8 @@ package com.x8bit.bitwarden.data.platform.manager.flightrecorder
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import com.bitwarden.annotation.OmitFromCoverage
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.data.util.toFormattedPattern
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.x8bit.bitwarden.BuildConfig
|
||||
import com.x8bit.bitwarden.data.platform.datasource.disk.model.FlightRecorderDataSet
|
||||
import com.x8bit.bitwarden.data.vault.manager.FileManager
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.x8bit.bitwarden.data.platform.manager.garbage
|
||||
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
@@ -57,7 +57,7 @@ sealed class NotificationPayload {
|
||||
@JsonNames("Date", "date")
|
||||
val date: ZonedDateTime?,
|
||||
|
||||
@JsonNames("PushNotificationLogOutReason", "pushNotificationLogOutReason")
|
||||
@JsonNames("Reason", "reason")
|
||||
val pushNotificationLogOutReason: PushNotificationLogOutReason?,
|
||||
) : NotificationPayload()
|
||||
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
package com.x8bit.bitwarden.data.platform.manager.model
|
||||
|
||||
import androidx.annotation.Keep
|
||||
import com.bitwarden.core.data.serializer.BaseEnumeratedIntSerializer
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Enumerated values to represent the possible reasons for a log out push notification
|
||||
*/
|
||||
@Serializable(with = PushNotificationLogOutReasonSerializer::class)
|
||||
enum class PushNotificationLogOutReason {
|
||||
@SerialName("0")
|
||||
KDF_CHANGE,
|
||||
}
|
||||
|
||||
@Keep
|
||||
private class PushNotificationLogOutReasonSerializer :
|
||||
BaseEnumeratedIntSerializer<PushNotificationLogOutReason>(
|
||||
className = "PushNotificationLogOutReason",
|
||||
values = PushNotificationLogOutReason.entries.toTypedArray(),
|
||||
)
|
||||
|
||||
@@ -4,13 +4,13 @@ import android.os.Parcelable
|
||||
import androidx.credentials.CredentialManager
|
||||
import com.bitwarden.cxf.model.ImportCredentialsRequestData
|
||||
import com.bitwarden.ui.platform.manager.share.model.ShareData
|
||||
import com.bitwarden.ui.platform.model.TotpData
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillSaveItem
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillSelectionData
|
||||
import com.x8bit.bitwarden.data.credentials.model.CreateCredentialRequest
|
||||
import com.x8bit.bitwarden.data.credentials.model.Fido2CredentialAssertionRequest
|
||||
import com.x8bit.bitwarden.data.credentials.model.GetCredentialsRequest
|
||||
import com.x8bit.bitwarden.data.credentials.model.ProviderGetPasswordCredentialRequest
|
||||
import com.x8bit.bitwarden.ui.vault.model.TotpData
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.x8bit.bitwarden.data.platform.manager.network
|
||||
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.data.repository.ServerConfigRepository
|
||||
import com.bitwarden.network.BitwardenServiceClient
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
|
||||
@@ -7,8 +7,8 @@ import android.net.Network
|
||||
import android.net.NetworkCapabilities
|
||||
import android.net.NetworkCapabilities.SIGNAL_STRENGTH_UNSPECIFIED
|
||||
import android.net.NetworkRequest
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.data.repository.util.bufferedMutableSharedFlow
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.model.NetworkConnection
|
||||
import com.x8bit.bitwarden.data.platform.manager.model.NetworkSignalStrength
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
@@ -43,3 +43,9 @@ inline fun <reified T : PolicyInformation> getPolicyTypeJson(): PolicyTypeJson =
|
||||
)
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Helper method for verifying if user has enabled the restrict item policy.
|
||||
*/
|
||||
fun PolicyManager.hasRestrictItemTypes(): Boolean =
|
||||
getActivePolicies(type = PolicyTypeJson.RESTRICT_ITEM_TYPES)
|
||||
.any { it.isEnabled }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.x8bit.bitwarden.data.platform.manager.util
|
||||
|
||||
import com.bitwarden.cxf.model.ImportCredentialsRequestData
|
||||
import com.bitwarden.ui.platform.model.TotpData
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillSaveItem
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillSelectionData
|
||||
import com.x8bit.bitwarden.data.credentials.model.CreateCredentialRequest
|
||||
@@ -8,7 +9,6 @@ import com.x8bit.bitwarden.data.credentials.model.Fido2CredentialAssertionReques
|
||||
import com.x8bit.bitwarden.data.credentials.model.GetCredentialsRequest
|
||||
import com.x8bit.bitwarden.data.credentials.model.ProviderGetPasswordCredentialRequest
|
||||
import com.x8bit.bitwarden.data.platform.manager.model.SpecialCircumstance
|
||||
import com.x8bit.bitwarden.ui.vault.model.TotpData
|
||||
|
||||
/**
|
||||
* Returns [AutofillSaveItem] when contained in the given [SpecialCircumstance].
|
||||
|
||||
@@ -15,12 +15,12 @@ import com.bitwarden.authenticatorbridge.util.decrypt
|
||||
import com.bitwarden.authenticatorbridge.util.encrypt
|
||||
import com.bitwarden.authenticatorbridge.util.toFingerprint
|
||||
import com.bitwarden.authenticatorbridge.util.toSymmetricEncryptionKeyData
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.core.util.isBuildVersionAtLeast
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.ui.platform.util.getTotpDataOrNull
|
||||
import com.x8bit.bitwarden.data.auth.manager.AddTotpItemFromAuthenticatorManager
|
||||
import com.x8bit.bitwarden.data.platform.repository.AuthenticatorBridgeRepository
|
||||
import com.x8bit.bitwarden.data.platform.util.createAddTotpItemFromAuthenticatorIntent
|
||||
import com.x8bit.bitwarden.ui.vault.util.getTotpDataOrNull
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.x8bit.bitwarden.data.platform.repository
|
||||
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.data.repository.model.Environment
|
||||
import com.bitwarden.data.repository.util.toEnvironmentUrls
|
||||
import com.bitwarden.data.repository.util.toEnvironmentUrlsOrDefault
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.x8bit.bitwarden.data.platform.repository
|
||||
|
||||
import android.view.autofill.AutofillManager
|
||||
import com.bitwarden.authenticatorbridge.util.generateSecretKey
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.network.model.PolicyTypeJson
|
||||
import com.bitwarden.network.model.SyncResponseJson
|
||||
import com.bitwarden.ui.platform.feature.settings.appearance.model.AppTheme
|
||||
@@ -29,6 +29,7 @@ import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
@@ -278,7 +279,7 @@ class SettingsRepositoryImpl(
|
||||
get() = activeUserId
|
||||
?.let { userId ->
|
||||
authDiskSource
|
||||
.getUserBiometicUnlockKeyFlow(userId)
|
||||
.getUserBiometricUnlockKeyFlow(userId)
|
||||
.map { it != null }
|
||||
}
|
||||
?: flowOf(false)
|
||||
@@ -293,7 +294,11 @@ class SettingsRepositoryImpl(
|
||||
?.let { userId ->
|
||||
authDiskSource
|
||||
.getPinProtectedUserKeyFlow(userId)
|
||||
.map { it != null }
|
||||
.combine(
|
||||
authDiskSource.getPinProtectedUserKeyEnvelopeFlow(userId),
|
||||
) { pinProtectedUserKey, pinProtectedUserKeyEnvelope ->
|
||||
pinProtectedUserKey != null || pinProtectedUserKeyEnvelope != null
|
||||
}
|
||||
}
|
||||
?: flowOf(false)
|
||||
|
||||
@@ -403,7 +408,7 @@ class SettingsRepositoryImpl(
|
||||
?.userDecryptionOptions
|
||||
?.hasMasterPassword != false
|
||||
val timeoutAction = settingsDiskSource.getVaultTimeoutAction(userId = userId)
|
||||
val hasPin = authDiskSource.getPinProtectedUserKey(userId = userId) != null
|
||||
val hasPin = authDiskSource.getPinProtectedUserKeyEnvelope(userId = userId) != null
|
||||
val hasBiometrics = authDiskSource.getUserBiometricUnlockKey(userId = userId) != null
|
||||
// The timeout action cannot be "lock" if you do not have master password, pin, or
|
||||
// biometrics unlock enabled.
|
||||
@@ -527,21 +532,27 @@ class SettingsRepositoryImpl(
|
||||
val userId = activeUserId ?: return
|
||||
unconfinedScope.launch {
|
||||
vaultSdkSource
|
||||
.derivePinKey(
|
||||
.enrollPin(
|
||||
userId = userId,
|
||||
pin = pin,
|
||||
)
|
||||
.fold(
|
||||
onSuccess = { derivePinKeyResponse ->
|
||||
onSuccess = { enrollPinResponse ->
|
||||
authDiskSource.apply {
|
||||
storeEncryptedPin(
|
||||
userId = userId,
|
||||
encryptedPin = derivePinKeyResponse.encryptedPin,
|
||||
encryptedPin = enrollPinResponse.userKeyEncryptedPin,
|
||||
)
|
||||
storePinProtectedUserKeyEnvelope(
|
||||
userId = userId,
|
||||
pinProtectedUserKeyEnvelope =
|
||||
enrollPinResponse.pinProtectedUserKeyEnvelope,
|
||||
inMemoryOnly = shouldRequireMasterPasswordOnRestart,
|
||||
)
|
||||
// Remove any legacy pin protected user keys.
|
||||
storePinProtectedUserKey(
|
||||
userId = userId,
|
||||
pinProtectedUserKey = derivePinKeyResponse.pinProtectedUserKey,
|
||||
inMemoryOnly = shouldRequireMasterPasswordOnRestart,
|
||||
pinProtectedUserKey = null,
|
||||
)
|
||||
}
|
||||
},
|
||||
@@ -561,6 +572,10 @@ class SettingsRepositoryImpl(
|
||||
userId = userId,
|
||||
encryptedPin = null,
|
||||
)
|
||||
authDiskSource.storePinProtectedUserKeyEnvelope(
|
||||
userId = userId,
|
||||
pinProtectedUserKeyEnvelope = null,
|
||||
)
|
||||
authDiskSource.storePinProtectedUserKey(
|
||||
userId = userId,
|
||||
pinProtectedUserKey = null,
|
||||
@@ -625,17 +640,38 @@ class SettingsRepositoryImpl(
|
||||
?.policyInformation as? PolicyInformation.VaultTimeout
|
||||
?: return
|
||||
|
||||
// Adjust the user's timeout or method if necessary to meet the policy requirements.
|
||||
vaultUnlockPolicy.minutes?.let { maxMinutes ->
|
||||
if ((vaultTimeout.vaultTimeoutInMinutes ?: Int.MAX_VALUE) > maxMinutes) {
|
||||
vaultTimeout = VaultTimeout.Custom(maxMinutes)
|
||||
when (vaultUnlockPolicy.type) {
|
||||
PolicyInformation.VaultTimeout.Type.NEVER -> {
|
||||
vaultTimeout = VaultTimeout.Never
|
||||
}
|
||||
|
||||
PolicyInformation.VaultTimeout.Type.ON_APP_RESTART,
|
||||
PolicyInformation.VaultTimeout.Type.ON_SYSTEM_LOCK,
|
||||
-> {
|
||||
vaultTimeout = VaultTimeout.OnAppRestart
|
||||
}
|
||||
|
||||
PolicyInformation.VaultTimeout.Type.IMMEDIATELY -> {
|
||||
vaultTimeout = VaultTimeout.Immediately
|
||||
}
|
||||
|
||||
PolicyInformation.VaultTimeout.Type.CUSTOM,
|
||||
null,
|
||||
-> {
|
||||
// Null values are treated as CUSTOM for legacy servers that do no provide a type.
|
||||
// Is there isn't a minutes value or if the current value is within range, we
|
||||
// leave everything alone.
|
||||
vaultUnlockPolicy.minutes?.let { maxMinutes ->
|
||||
if ((vaultTimeout.vaultTimeoutInMinutes ?: Int.MAX_VALUE) > maxMinutes) {
|
||||
vaultTimeout = VaultTimeout.Custom(maxMinutes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
vaultUnlockPolicy.action?.let {
|
||||
vaultTimeoutAction = if (it == "lock") {
|
||||
VaultTimeoutAction.LOCK
|
||||
} else {
|
||||
VaultTimeoutAction.LOGOUT
|
||||
vaultTimeoutAction = when (it) {
|
||||
PolicyInformation.VaultTimeout.Action.LOCK -> VaultTimeoutAction.LOCK
|
||||
PolicyInformation.VaultTimeout.Action.LOGOUT -> VaultTimeoutAction.LOGOUT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.x8bit.bitwarden.data.platform.repository.di
|
||||
|
||||
import android.view.autofill.AutofillManager
|
||||
import com.bitwarden.data.manager.DispatcherManager
|
||||
import com.bitwarden.core.data.manager.dispatcher.DispatcherManager
|
||||
import com.bitwarden.data.repository.ServerConfigRepository
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
||||
import com.x8bit.bitwarden.data.autofill.accessibility.manager.AccessibilityEnabledManager
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user