Mark M. | has entered the room |
Mark M. | turned on guest access |
Dec 1 | 4:00 PM |
sumeet-thadani | has entered the room |
sumeet-thadani |
Hi Mark, I subscribed to the service per your email
|
Mark M. |
hello, Sumeet!
|
sumeet-thadani |
I want to talk about the stack trace
|
sumeet-thadani |
I can copy it here
|
Mark M. |
OK
|
Mark M. |
that's not necessary, since I already have it
|
Rick R. | has entered the room |
Mark M. |
(unless you have a new and exciting one)
|
Mark M. |
(BTW, hello Rick -- I'll be with you shortly!0
|
sumeet-thadani |
No it's the same on
|
sumeet-thadani |
So it seems the interesting lines of code are:
|
Mark M. |
OK
|
sumeet-thadani |
View paste
|
sumeet-thadani |
the last line throws a SecurityException
|
Mark M. |
yes
|
sumeet-thadani |
View paste
|
sumeet-thadani |
I think we meet both conditions
|
Mark M. |
that's from Android 6.0
|
Mark M. |
are you sure about the second one?
|
sumeet-thadani |
yes
|
Mark M. |
OK
|
Mark M. |
perhaps in Android 5.x, the check was a bit different
|
Mark M. |
you
|
sumeet-thadani |
because PrestoNotificationListener is a subclass of NotificationListenerService
|
sumeet-thadani |
and it's clearly being started
|
Dec 1 | 4:05 PM |
Mark M. |
is there any way that it can be started?
|
sumeet-thadani |
the code in LollipopMusicController's constructor gets called from the onStartCommend function in PrestoNotificationListener
|
Mark M. |
for example, do you have another <action> besides android.service.notification.NotificationListenerService?
|
Mark M. |
if there is another way to start that service, you don't necessarily know that the user activated you as a notification listener
|
sumeet-thadani |
I don't folow the question
|
sumeet-thadani |
no
|
sumeet-thadani |
not that I know of
|
Mark M. |
OK
|
sumeet-thadani |
We make users to to the settings page and give us requisite permissions
|
sumeet-thadani |
in the app
|
Mark M. |
then I'm back to: perhaps in Android 5.x, the check was a bit different
|
sumeet-thadani |
The strange thing is that it works for about 75 of users
|
sumeet-thadani |
that's 75%
|
Mark M. |
you would need to grab the AOSP code for some Android version that you see the crash on, and search for that specific string ("Missing permission to control media")
|
Mark M. |
to see what's raising it and why
|
sumeet-thadani |
OK, one other hypothesis
|
Mark M. |
actually, let me take a question from Rick, and I'll be back with you in a moment
|
Mark M. |
Rick: your turn! do you have a question?
|
sumeet-thadani |
Mark what class was that enforceMediaPermissions function in?
|
Mark M. |
Rick: if you come up with a question, let me know -- in the meantime, I'll swing back to Sumeet
|
Mark M. |
MediaSessionService
|
Mark M. | |
Dec 1 | 4:10 PM |
Rick R. |
hi
|
Mark M. |
hi, Rick! do you have a question?
|
Rick R. |
i was waiting until you finished with sumeet... mine is pretty simple since i'm new to android programming...
|
Rick R. |
you mention you can bump stack overflow questions with a subscription? how exactly do you do that?
|
Mark M. |
I like to alternate questions, as otherwise I might not get to everyone
|
Mark M. |
log into the Warescription site (https://wares.commonsware.com)
|
Mark M. |
in the nav bar at the top, Stack Overflow Bump is in the Other Stuff drop-down
|
Mark M. |
you basically paste in a link to the question
|
Mark M. |
if it meets the criteria (at least 1 day old, tagged with android), I'll get an email
|
Mark M. |
and I'll take a look at the question when I can
|
Rick R. |
oh now i see it!one
|
Mark M. |
usually, it's fairly quick, so long as I'm not sleeping or something :-)
|
Rick R. |
cool. so the one i posted was here i was curious about it from the book...
|
Rick R. | |
Mark M. |
I don't use IDEA, so I'm not sure what's going on there
|
Rick R. |
don't use use andoid stuido?
|
Mark M. |
Android Studio ~= IDEA
|
Mark M. |
there are differences
|
Rick R. |
well sort of true i guess
|
Mark M. |
in terms of why drawable-... was not updated, that's because you said it was a launcher icon, presumably
|
Rick R. |
they changed that much you think in the plugin?
|
Mark M. |
for that particular asset type, they generate mipmap values, not drawable values
|
Mark M. |
whether something uses mipmap-... versus drawable-... is based on your app itself (e.g., android:icon in the manifest)
|
Rick R. |
ah ok.. i was following what it said on page 110 of the latest edition
|
Dec 1 | 4:15 PM |
Mark M. |
if android:label="@mipmap/ic_launcher", it uses the mipmap
|
Mark M. |
if android:label="@drawable/ic_launcher", it uses the drawable
|
Mark M. |
page 110 demonstrates importing the asset as a mipmap
|
Rick R. |
ok but the example were' on at that stage in the book has it as a launcher in the AndroidManifest..
|
Rick R. | |
Mark M. |
um
|
Mark M. | |
Mark M. |
same with the starter project from GitHub
|
Mark M. | |
Mark M. |
it has @mipmap/ic_launcher, not @drawable/ic_launcher
|
sumeet-thadani |
Mark do you know the tagging convention they use so I can find the right version?
|
Rick R. |
wow.. ok wonder how i managed to have that one. i swore i had gotten the latest code I thought.
|
Mark M. |
so, I am not quite certain where you got the @drawable/ic_launcher from
|
Rick R. |
thanks though! great book love the way it's laid out
|
Rick R. |
ill start from scratch with a fresh one
|
Mark M. |
thanks! let me swing back to Sumeet for a bit, and I'll come back to you shortly
|
Mark M. |
Sumeet: um, I think you want android-cts-... for some relevant version
|
Mark M. |
AFAIK, the _rN suffix is the patchlevel
|
Mark M. |
but I'm not super-expert at the AOSP tagging system, so YMMV
|
Dec 1 | 4:20 PM |
Mark M. |
it's also possible that the same error string is raised elsewhere in Android 5.x
|
Mark M. |
I don't know of a way to search GitHub within a particular tagged edition of the source
|
Mark M. |
which is why I suspect you'll need to download it
|
sumeet-thadani |
the function looks the same in android-cts-5.1-r4
|
Mark M. |
that happened to be the version I picked just now, and yes, it seems to be the same
|
Mark M. |
which means that one of three things is happening:
|
Mark M. |
1. that same message is raised elsewhere in Android 5.x
|
Mark M. |
2. the problem is in some custom ROM (manufacturer or independent), or
|
Mark M. |
3. your assumption about your service only being invoked if it is set up as a notification listener is incorrect
|
sumeet-thadani |
yes I see the problem on 5.0, 5.0.1, 5.1, 5.1.1
|
sumeet-thadani |
It does not seem device specific
|
sumeet-thadani |
I looked into that.
|
sumeet-thadani |
I have one hypothesis
|
sumeet-thadani |
when I call this line List<MediaController> controllers = mediaSessionManager.getActiveSessions(notificationListener);
|
Dec 1 | 4:25 PM |
sumeet-thadani |
the notification listener being passed in is not yet started
|
sumeet-thadani |
onStartCommand calls the function which calls the offending line
|
sumeet-thadani |
do you think that matters>
|
Mark M. |
enforceMediaPermissions() wouldn't seem to care about tht
|
Mark M. |
er, that
|
Mark M. |
but, I haven't traced through isEnabledNotificationListener(), which would be where that all comes from
|
Mark M. |
yeah, that just seems to check Settings to see if the user set up your app as being an enabled listener
|
sumeet-thadani |
yes true, there's an assumption there on my part.
|
Mark M. |
its possible this is tied to secondary user accounts, but I don't get the sense that they're too popular
|
Mark M. |
so I'd be somewhat surprised if you got a substantial percentage of crashes that way
|
Mark M. |
let me switch back to Rick, if he has another question, and I'll be back with you in a bit
|
Mark M. |
Rick: your turn! do you have another question?
|
Dec 1 | 4:30 PM |
Mark M. |
Rick: if you come up with another question, let me know
|
Mark M. |
Sumeet: back to you!
|
sumeet-thadani |
Do you think I need to add permissions to access SD Cards -- what if some media is stored externally?
|
Mark M. |
I haven't used the media session APIs
|
Mark M. |
are you working with the Uri of some media?
|
sumeet-thadani |
Not really we just get notified when media starts on the device
|
sumeet-thadani |
we use that to start gesture detection
|
Mark M. |
then I wouldn't think that you need READ_EXTERNAL_STORAGE
|
sumeet-thadani |
then use the gestures to control the music
|
Mark M. |
that should only be necessary if you're actually trying to read in the media itself
|
sumeet-thadani |
right
|
Mark M. |
and even then, there are no permissions for accessing removable media
|
sumeet-thadani |
it's weird that it works properly on our test devices
|
sumeet-thadani |
all the time
|
sumeet-thadani |
and it works for 75% of users
|
sumeet-thadani |
so it's either a timing issue
|
sumeet-thadani |
just not sure
|
Rick R. |
I'm great! Thanks for the help. No clue how I had that mangled project. Working great now. Ok now let me get back to learning. Awesome you have this office hours thing. I'll see you back at some point in the future I'm sure. I'll answer my own question on stackoverlow:)
|
Dec 1 | 4:35 PM |
Rick R. |
take care
|
Dec 1 | 4:35 PM |
Mark M. |
Rick: you too!
|
Rick R. | has left the room |
Mark M. |
what are you using for crash reporting?
|
Mark M. |
more specifically, does it give you any indication if the device has multiple accounts set up, and what account your app is running as?
|
sumeet-thadani |
crittercism
|
sumeet-thadani |
I can check
|
sumeet-thadani |
Also, I came across this question on SO
|
sumeet-thadani | |
Mark M. |
that falls under scenario #2 from my earlier list, more or less
|
sumeet-thadani |
Is there anything I can do about that?
|
Mark M. |
not really
|
Mark M. |
wrap your call in a try/catch block, and fail gracefully
|
Mark M. |
you could call checkPermission() on PackageManager to see if somebody ripped out the permission from the app and repackaged it
|
Mark M. |
but, even if they did, there's nothing you can do to somehow add it back
|
Dec 1 | 4:40 PM |
sumeet-thadani |
So I was just looking at the code, and there are places where we call startService with an explicit intent for PrestoNotificationListener
|
sumeet-thadani |
How would that kill us
|
sumeet-thadani |
?
|
Mark M. |
well, if the user has not yet enabled you as a notification listener, that would explain the symptoms
|
Mark M. |
you could do the same check that the platform does (see isEnabledNotificationListener() in that MediaSessionService class) to see if you are indeed enabled
|
Mark M. |
or, if the explicit-Intent scenario is distinctly different from the notification-listener scenario, perhaps they should be separate services, with the explicit-Intent one not trying to use the media session APIs
|
Dec 1 | 4:45 PM |
Mark M. |
BTW, if you have any other questions, go right ahead
|
Dec 1 | 4:50 PM |
sumeet-thadani |
I am just thinking things through
|
Mark M. |
no worries
|
Dec 1 | 4:55 PM |
sumeet-thadani |
I am going to try a couple of things and see if we do better
|
Mark M. |
OK
|
Dec 1 | 5:00 PM |
Mark M. |
well, that's a wrap for today's chat
|
Mark M. |
the transcript will be posted to https://commonsware.com/office-hours/ shortly
|
Mark M. |
the next chat is tomorrow at 9am US Eastern
|
Mark M. |
have a pleasant day!
|
sumeet-thadani | has left the room |
Mark M. | turned off guest access |