Skip to content

Conversation

@Mia0451
Copy link
Contributor

@Mia0451 Mia0451 commented Jul 17, 2024

Use @classname annotation instead of looseSignatures.

Overview

Both class FontResourceParser and FontResourceParser$FamilyResourceEntry are added in API 26
https://github.com/AndroidSDKSources/android-sdk-sources-for-api-level-26/blob/master/android/content/res/FontResourcesParser.java#L42

FontFamily is added in API 21 (robolectric support start from api 21)
https://github.com/AndroidSDKSources/android-sdk-sources-for-api-level-21/blob/master/android/graphics/FontFamily.java

both class FontConfig and FontConfig$Alias are added in API 26
https://github.com/AndroidSDKSources/android-sdk-sources-for-api-level-26/blob/master/android/text/FontConfig.java#L133

Proposed Changes

@HiddenApi
@Implementation
protected static Typeface createFromFamilies(Object /*FontFamily[]*/ families) {
protected static Typeface createFromFamilies(FontFamily[] families) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FontFamily was added in AOSP when they develop Android SDK 21, but it is not public directly as it was @hide in Android SDK 21. Actually, it is opened to developers from Android SDK 29: https://developer.android.com/reference/android/graphics/fonts/FontFamily?hl=en.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emm, so I should still use ClassName annotation with Object type instead of using FontFamily type directly such as protected static Typeface createFromFamilies(FontFamily[] families)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I think this method should use ClassName for FontFamily array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @utzcoz,
still confused why we need ClassName annotation here, since protected static Typeface createFromFamilies(FontFamily[] families) in this shadow is marked HiddenApi and protected, looks like other developer will not be able to access this function directly? thus no way to access FontFamily class?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. HiddenApi is not accessible by normal developers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some APIs in AOSP with public modifier, but they are marked by HiddenApi, SystemApi, or @hide. These APIs are not packaged into public API list to developers as AOSP's tools will skip them. When we add customized APIs to AOSP, we often do similar things.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think Robolectric's HiddenApi is just an annotation to mark shadow APIs to show that origin APIs are marked by Hidden.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @utzcoz ,
thanks for the detailed explanation, very informative.
I am still confused why not use the type explicitly. so

  1. FontFamily was added in AOSP when they develop Android SDK 21
  2. protected modifier
    These two will guarantee
  3. Class resolution will be good since the class is indeed in the sdk
  4. Normal developers will not be able to call ShadowLegacyType#createFromFamilies directly since it is protected?

@Mia0451 Mia0451 force-pushed the feat/replace_loose_signatures_part26 branch from f526645 to 1e9c2c9 Compare July 18, 2024 06:54
@Mia0451 Mia0451 force-pushed the feat/replace_loose_signatures_part26 branch from 1e9c2c9 to 02ee741 Compare July 26, 2024 03:12
@utzcoz
Copy link
Member

utzcoz commented Jul 26, 2024

@Mia0451 There are some failed tests on CI.

Use @classname annotation instead of looseSignatures.
@Mia0451
Copy link
Contributor Author

Mia0451 commented Jul 26, 2024

fixed failing test

@Mia0451 Mia0451 force-pushed the feat/replace_loose_signatures_part26 branch from 02ee741 to c022409 Compare July 26, 2024 06:54
@utzcoz utzcoz merged commit cdda95e into robolectric:master Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants