Office Hours — Today, September 21

Tuesday, September 19

Mark M.
has entered the room
Mark M.
turned on guest access
Sep 21
9:20 AM
Susheel
has entered the room
Mark M.
hello, Susheel!
how can I help you today?
Susheel
Hi Mark. How are you doing?
Mark M.
slightly sleep-deprived, but otherwise OK -- and you?
Susheel
I got just the right amount of sleep so I'm good. Thank you!
9:25 AM
Susheel
I have a horizontal recyclerview I am using this as a viewpager. But now I'm having to implement my own viewpager indicator equivalent.
Shouldn't be terribly hard as I could just use shape drawables because I am in need of circle page indicator.
I know there's nothing in stock recyclerview that provides this functionality
What do you think or suggest?
Mark M.
in terms of... what?
Dimitris
has entered the room
Mark M.
(BTW, hello, Dmitris -- I will be with you shortly!)
Susheel
about my solution. with the shape drawables
Dimitris
Hello!
Susheel
is there a simpler, cleaner or elegant way?
Mark M.
::shrug::
that seems fine
you might look at how an equivalent ViewPager indicator is implemented
the principle difference is in the event listener for finding out when to change the indicator, and to what state
(er, principal)
Susheel
Right.
Okay
Mark M.
everything else about the indicator would not need to change
barring some unexpected dependency of the indicator on the pager
Susheel
True. You can get to Dimitris now.
Mark M.
OK
Dmitris: your turn! do you have a question?
Dimitris
So in case we are using a "bad" library that creates some thread using C++ and its not properly mapped to java so when the device sleeps and come back the c++ created thread is either killed or sleeping but we need to restart it, what do we do :P
Mark M.
we ask that question of somebody who has done a lot more NDK work than I have
Dimitris
(library is handed by the manufacturer and its obfuscated)
9:30 AM
Mark M.
as I haven't the foggiest notion
9:30 AM
Mark M.
though if it's the manufacturer's own library, they ought to know about their own hardware sleeping, and so this is clearly a bug
Dimitris
I guess if I dont see any memory leaks I should just restart it manually without fear right ?
Mark M.
ideally, yes
it is possible that there is some global state outside the scope of the thread that will not like that, though
Dimitris
and what is the "best" way of getting notified that the device goes to sleep
Mark M.
AFAIK, the closest thing is watching for ACTION_SCREEN_OFF and ACTION_SCREEN_ON broadcasts
but, I have not researched this area in years
Dimitris
thats not really reliable
Mark M.
that would not surprise me
but I am not aware of anything better
Dimitris
cause this definitely does't seem to recognize the user pressing the power button
Mark M.
it should
Dimitris
what about recognizing the power button click
maybe I should override the keys pressed
Mark M.
AFAIK, people do that via ACTION_SCREEN_OFF and ACTION_SCREEN_ON
Dimitris
hmm then I guess I should check if I have some mistake in my code
Mark M.
I do not think that the power button triggers a KeyEvent, though I may be wrong, and that would also imply that your activity is in the foreground
again, this is not an area that I work in much, so my knowledge is fuzzy and may be out of date
IOW, YMMV, FYI :-)
Dimitris
:D
9:35 AM
Dimitris
adb shell input keyevent 26 is the power button :P
Mark M.
however, if your code cannot detect it, that will be of limited utility
Dimitris
hmm
Mark M.
for example, HOME button presses do not result in KeyEvents, last I checked
Dimitris
maybe I can use this onWindowFocusChanged
im not sure if on screen on this gets triggered
if it does I can assume the device wakes up
Mark M.
it would get triggered in other cases, though, such as when another activity takes over the focus
Dimitris
hmm
if I could at least consistently get the screen off event
the combination would work
but I need at least one of the events in a consistent way
Mark M.
pressing the POWER button should trigger ACTION_SCREEN_OFF, AFAIK
if it is not doing that on your hardware, ask the manufacturer
Dimitris
thank you Mark !
Mark M.
for stuff like this, you might run some tests on a more "official" environment (e.g., Google Pixel), to determine whether your problem is in your logic or in the manufacturer's device
Dimitris
this makes sense !
Mark M.
let me switch back to Susheel, and I will return to you in a bit
Susheel: back to you! do you have another question?
Dimitris
(at least allows me to complain to the manufacturer)
9:40 AM
Mark M.
OK, if either of you have a question, go right ahead
Dimitris
What is your opinion of global shared preferences and the fact that its deprecated, wasn't it a decent feature for people having a set of applications with sharedUserId?
Mark M.
I don't think it was ever really safe for multiple processes
Dimitris
Do you know if an app has System permissions (signed with a system key and so on) can it read shared prefs from every app on the device
Mark M.
I doubt it
that should require root
Dimitris
what if two apps are both system apps
Mark M.
that should not change the situation
Dimitris
can they access each others shared prefs ?
Mark M.
a device manufacturer/ROM developer might set up a pre-installed app in some Linux user group that allows for broader read access
not by default
as Google recommends, use a real IPC solution
9:45 AM
Dimitris
but they also mention this
The name of a Linux user ID that will be shared with other applications. By default, Android assigns each application its own unique user ID. However, if this attribute is set to the same value for two or more applications, they will all share the same ID — provided that their certificate sets are identical. Applications with the same user ID can access each other's data and, if desired, run in the same process.
each other's data means shared prefs too ?
Mark M.
yes
Dimitris
so if the sharedUserId = System
then it might be possible that they both access the same
Mark M.
by "system apps", I assumed that you mean installed on the privileged partition
Dimitris
shareduserid='android.uid.system’
Mark M.
are you signing the firmware?
if not, then what you want will not work, as your apps will not be signed with the signing key that signed the firmware
Dimitris
no but I can sign my app with the OS key
Mark M.
OK
then in principle what you describe should be possible
Dimitris
so I do have a real System app
thank you !
is there a section on IPC in the book ?
Mark M.
startActivity(), startService(), bindService(), sendBroadcast() are your main IPC solutions
(plus ContentProvider)
(and its related classes, like ContentObserver)
so I would have one app be the "owner" of the preferences, and expose an API to other apps via a provider or perhaps a bound service
Dimitris
bad question but is the ContentProvider staying intact when an app gets uninstalled
9:50 AM
Mark M.
no, as the ContentProvider implementation is being uninstalled
Susheel
has left the room
Dimitris
that makes sense
Mark M.
IMHO, if you have two apps that are that tightly coupled, they should be one app, not two
Dimitris
I guess the provider or bound service implementations are the way to go for me
they need to be two unfortunately
so I need to decide how they will communicate
maybe broadcasting some intents will be enough
but thank you for mentioning all the options
have a nice day Mark thanks again
Mark M.
you're welcome!
Dimitris
has left the room
10:00 AM
Mark M.
turned off guest access

Tuesday, September 19

 

Office Hours

People in this transcript

  • Dimitris
  • Mark Murphy
  • Susheel