r/androiddev • • Sep 21 '17

Android Color Resources Not Safe

https://twitter.com/mandybess/status/910555678476951552
238 Upvotes

36 comments sorted by

25

u/jpetitto Sep 21 '17

I suppose this extends to other resources too, like android:string/ok.

23

u/MrPineappleHat Sep 21 '17

I wouldn't use android:string unless you've translated your app to the same languages as the Android platform. And that almost certainly varies by OEM too. Otherwise your users can see some strings in one language and some in another, depending on their locale. 🙃

3

u/maybe-ios-dev Sep 21 '17

I think adding a resConfigs to your gradle file to strip unused language resources would avoid that problem, no?

4

u/MrPineappleHat Sep 21 '17

I'm pretty sure that won't work. That will simply remove strings from some languages from your app. The issue is that the strings reside on the phone. That's why you can't predict what they are.

There might be a way to say "only show my app in languages X, Y, and Z" but I don't know off hand.

14

u/ErnestGrz Sep 21 '17

I'm pretty sure I've seen that issue before. Ok sometimes being "okay" or "done"

51

u/EddieRingle Sep 21 '17

There's a part of the CTS that checks to make sure the Holo and Material themes are unmodified. I would've hoped that there was a similar test to ensure public framework resources were left unmodified, as well.

10

u/[deleted] Sep 27 '17

We naively hoped OEMs would not change android.R.color... A new test is getting added https://android-review.googlesource.com/#/c/platform/cts/+/494605/

3

u/EddieRingle Sep 27 '17

Awesome! What's done is done, but I'm glad to see improvements are being made.

20

u/cypressious Sep 21 '17

This! This is 100% on Google.

23

u/adamhighdef Sep 21 '17

No, it's on OEMs for changing them in the first place. Not every android phone is bundled with googles software

10

u/TheRealKidkudi Sep 21 '17

¿Por que no los dos? Yeah OEMs shouldn't be messing with it, but Google shouldn't let them do it either.

4

u/[deleted] Sep 23 '17

It's impossible to enumerate all possible bad things that can be done. Google has the same problem with SELinux neverallow rules trying to rule out all kinds of bad policies. The only full solutions would be the OEMs acting responsibility or Google ending their Play licensing and treating Android like ChromeOS.

3

u/wannagotopopeyes Oct 04 '17

No, it's on Google for letting this kind of thing slip through the cracks. Compatibility Test Suite is a requirement for all OEM's shipping a device with Android - not sure how this sort of thing would slip through but Google won't let you make any Android hardware if you fail CTS

41

u/ene__im https://github.com/eneim Sep 21 '17

The worst part is when they change transparent to solid color. Had this issue before when working with some Japanese tablets.

12

u/fritti_tailchaser Sep 21 '17

I wonder what the rationale for doing that is.

11

u/el_bhm Sep 21 '17

From what I gathered it was optimization for the display matrix or display hardware driver. Either it was slightly more efficient or faster to draw slightly opaque color than fully transparent. Don't quote me on that though. Rather someone correct me please.

17

u/adamhighdef Sep 21 '17

From what I gathered it was optimization for the display matrix or display hardware driver. Either it was slightly more efficient or faster to draw slightly opaque color than fully transparent.

  • el_bhm 2017

5

u/[deleted] Oct 11 '17

Good bot.

17

u/fury-s12 Sep 21 '17

usually its just that samsung think they are right, always

11

u/xroni Sep 21 '17

Since Samsung is Korean they don't make Japanese tablets afaik, but yeah they think they can do whatever they want.

5

u/[deleted] Sep 21 '17

It's because they can. They hold by far the largest market share, and a few fuckups here and there ain't gonna change that.

1

u/ene__im https://github.com/eneim Sep 21 '17

I was so angry and tired that I forgot to ask "WHY" ...

1

u/[deleted] Sep 21 '17

Not supporting an alpha channel maybe? I have no idea, but saving a byte for every pixel seems nice for budget devices.

21

u/beejiu Sep 21 '17

On a web application I work on, I discovered one day that (white) text on (blue) buttons seemed quite difficult to read. Turns out my colleague thought it would be a good idea to change a variable called $cpurewhite to have a blueish hint.

13

u/shvelo Tbilisi Bus Sep 21 '17

OEMs are the biggest enemy of good Android experience.

26

u/can_i_have Sep 21 '17

I argued this case with a senior architect fuckin yearsss back in 2013. Going to find his contact info so that I can have the last laugh.

10

u/Shaper_pmp Sep 21 '17

I genuinely can't reconstruct any rational chain of thought that says this is even ok, let alone a good idea.

All I can assume is that I just haven't hit myself enough times in the head with a brick to understand the "reasoning" behind it.

4

u/WestonP Sep 21 '17

Finally, clear justification for me being stubborn and defining my own colors! I've learned to be weary of trusting the system to be consistent.

1

u/K-K-K-KWEEEH Sep 21 '17

Could this happen in the Color class as well?

5

u/jpetitto Sep 21 '17

They are just compile time hex constants packaged with the SDK, so they should be safe. I hope.

1

u/RITheory Sep 21 '17

Iirc it's a lookup table, so probably not? Could be wrong though.

3

u/[deleted] Sep 21 '17

I'm going to guess that mapping the brightest colors to dimmer versions it lowers screen power usage and extends battery life.

2

u/Avamander Sep 21 '17 edited Oct 03 '24

Lollakad! Mina ja nuhk! Mina, kes istun jaoskonnas kogu ilma silma all! Mis nuhk niisuke on. Nuhid on nende eneste keskel, otse kõnelejate nina all, nende oma kaitsemüüri sees, seal on nad.

0

u/[deleted] Sep 21 '17

[deleted]

8

u/RITheory Sep 21 '17

What the hell

6

u/Realtrain Sep 21 '17

Love the username