xref: /aosp_15_r20/external/cronet/base/android/README.md (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker# //base/android
2*6777b538SAndroid Build Coastguard Worker
3*6777b538SAndroid Build Coastguard WorkerThis directory contains:
4*6777b538SAndroid Build Coastguard Worker
5*6777b538SAndroid Build Coastguard Worker* C++ APIs that are broadly useful and are unique to `target_os="android"`, and
6*6777b538SAndroid Build Coastguard Worker* Java APIs that are broadly useful, along C++ bindings when necessary.
7*6777b538SAndroid Build Coastguard Worker
8*6777b538SAndroid Build Coastguard WorkerThis directory does not contain Android-specific implementations / extensions
9*6777b538SAndroid Build Coastguard Workerto APIs declared directly in `//base`. Those live in `//base/*_android.cc`, or
10*6777b538SAndroid Build Coastguard Workerbehind `#ifdef`s.
11*6777b538SAndroid Build Coastguard Worker
12*6777b538SAndroid Build Coastguard Worker## Adding New APIs
13*6777b538SAndroid Build Coastguard Worker
14*6777b538SAndroid Build Coastguard WorkerThe advice laid out in [//base/README.md] applies to this directory as well.
15*6777b538SAndroid Build Coastguard WorkerThe bars for what APIs should exist and for code quality are generally higher
16*6777b538SAndroid Build Coastguard Workerthan for other directories. If you find yourself wanting to add a new API, you
17*6777b538SAndroid Build Coastguard Workershould expect that code reviews take multiple revisions and that they be met
18*6777b538SAndroid Build Coastguard Workerwith (respectful) scrutiny.
19*6777b538SAndroid Build Coastguard Worker
20*6777b538SAndroid Build Coastguard WorkerIf you are not sure whether an API would make sense to add, you can ask via
21*6777b538SAndroid Build Coastguard Worker[email protected].
22*6777b538SAndroid Build Coastguard WorkerIt is common to add APIs to `//chrome` (or elsewhere) first, and move them into
23*6777b538SAndroid Build Coastguard Worker`//base` after their usefulness has been proven.
24*6777b538SAndroid Build Coastguard Worker
25*6777b538SAndroid Build Coastguard Worker[//base/README.md]: /base/README.md
26*6777b538SAndroid Build Coastguard Worker
27*6777b538SAndroid Build Coastguard Worker### What Uses //base/android?
28*6777b538SAndroid Build Coastguard Worker
29*6777b538SAndroid Build Coastguard WorkerThe main two clients are Chrome and WebView, but it is also used by other
30*6777b538SAndroid Build Coastguard WorkerChromium-based apps, such as Chromecast and Chrome Remote desktop. Some
31*6777b538SAndroid Build Coastguard Worker`//base/android` classes are used by `//build` (this is a layering violation,
32*6777b538SAndroid Build Coastguard Workertracked in [crbug/1364192] and [crbug/1377351]).
33*6777b538SAndroid Build Coastguard Worker
34*6777b538SAndroid Build Coastguard WorkerTwo considerations for WebView:
35*6777b538SAndroid Build Coastguard Worker
36*6777b538SAndroid Build Coastguard Worker1. The application Context is that of the host app's.
37*6777b538SAndroid Build Coastguard Worker2. The UI thread might be different from the main thread.
38*6777b538SAndroid Build Coastguard Worker
39*6777b538SAndroid Build Coastguard Worker[crbug/1364192]: https://crbug.com/1364192
40*6777b538SAndroid Build Coastguard Worker[crbug/1377351]: https://crbug.com/1377351
41*6777b538SAndroid Build Coastguard Worker
42*6777b538SAndroid Build Coastguard Worker
43*6777b538SAndroid Build Coastguard Worker### New API Checklist
44*6777b538SAndroid Build Coastguard Worker
45*6777b538SAndroid Build Coastguard WorkerHere is a list of checks you should go through when adding a new API:
46*6777b538SAndroid Build Coastguard Worker
47*6777b538SAndroid Build Coastguard Worker1. The functionality does not already exist in system libraries (Java APIs,
48*6777b538SAndroid Build Coastguard Worker   Android SDK) or in already adopted `third_party` libraries, such as AndroidX.
49*6777b538SAndroid Build Coastguard Worker2. Reasonable effort has been made to ensure the new API is discoverable. E.g.:
50*6777b538SAndroid Build Coastguard Worker   Coordinate refactorings of existing patterns to it, add a [presubmit check],
51*6777b538SAndroid Build Coastguard Worker   to recommend it, etc.
52*6777b538SAndroid Build Coastguard Worker3. Tests (ideally Robolectric) are added.
53*6777b538SAndroid Build Coastguard Worker4. Thought has been put into API design.
54*6777b538SAndroid Build Coastguard Worker   * E.g. adding `@Nullable`, or `@DoNotMock`
55*6777b538SAndroid Build Coastguard Worker   * E.g. adding test helpers, such as `ForTesting()` methods or `TestRule`s
56*6777b538SAndroid Build Coastguard Worker   * E.g. adding asserts or comments about thread-safety
57*6777b538SAndroid Build Coastguard Worker   * E.g. could usage of the API be made harder to get wrong?
58*6777b538SAndroid Build Coastguard Worker
59*6777b538SAndroid Build Coastguard Worker[presumbit check]: https://chromium.googlesource.com/chromium/src/+/main/build/android/docs/java_toolchain.md#Static-Analysis-Code-Checks
60*6777b538SAndroid Build Coastguard Worker
61*6777b538SAndroid Build Coastguard Worker### Choosing a Reviewer
62*6777b538SAndroid Build Coastguard Worker
63*6777b538SAndroid Build Coastguard WorkerAll members of [`//base/android/OWNERS`] will be CC'ed on reviews through a
64*6777b538SAndroid Build Coastguard Worker[`//WATCHLIST`] entry. For new APIs, feel free to pick a reviewer at random.
65*6777b538SAndroid Build Coastguard WorkerFor modifying existing files, it is best to use a reviewer from prior changes to
66*6777b538SAndroid Build Coastguard Workerthe file.
67*6777b538SAndroid Build Coastguard Worker
68*6777b538SAndroid Build Coastguard Worker[`//base/android/OWNERS`]: /base/android/OWNERS
69*6777b538SAndroid Build Coastguard Worker[`//WATCHLIST`]: /WATCHLIST
70