Office Hours — Today, December 1

Saturday, November 28

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
I can copy it here
Mark M.
OK
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)
(BTW, hello Rick -- I'll be with you shortly!0
sumeet-thadani
No it's the same on
So it seems the interesting lines of code are:
Mark M.
OK
sumeet-thadani
View paste
 MediaSessionManager mediaSessionManager =
                (MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);

        ComponentName notificationListener = new ComponentName(
                context.getPackageName(), PrestoNotificationListener.class.getName());
        //Get currently active media sessions and parse controllers
        List<MediaController> controllers = mediaSessionManager.getActiveSessions(notificationListener);
the last line throws a SecurityException
Mark M.
yes
sumeet-thadani
View paste
What you said earlier private void enforceMediaPermissions(ComponentName compName, int pid,
int uid,
           int resolvedUserId) {
       if (isCurrentVolumeController(uid)) return;
       if (getContext()
               .checkPermission(android.Manifest.permission.MEDIA_CONTENT_CONTROL,
               pid, uid)
                   != PackageManager.PERMISSION_GRANTED
               && !isEnabledNotificationListener(compName,
               UserHandle.getUserId(uid),
                       resolvedUserId)) {
           throw new SecurityException("Missing permission to control
           media.");
       }
   }
I think we meet both conditions
Mark M.
that's from Android 6.0
are you sure about the second one?
sumeet-thadani
yes
Mark M.
OK
perhaps in Android 5.x, the check was a bit different
you
sumeet-thadani
because PrestoNotificationListener is a subclass of NotificationListenerService
and it's clearly being started
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?
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
no
not that I know of
Mark M.
OK
sumeet-thadani
We make users to to the settings page and give us requisite permissions
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
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")
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
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
MediaSessionService
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...
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
log into the Warescription site (https://wares.commonsware.com)
in the nav bar at the top, Stack Overflow Bump is in the Other Stuff drop-down
you basically paste in a link to the question
if it meets the criteria (at least 1 day old, tagged with android), I'll get an email
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...
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
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
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
4:15 PM
Mark M.
if android:label="@mipmap/ic_launcher", it uses the mipmap
if android:label="@drawable/ic_launcher", it uses the drawable
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..
View paste
 <application
        android:allowBackup="false"
        android:icon="@drawable/ic_launcher"
Mark M.
um
same with the starter project from GitHub
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
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
Sumeet: um, I think you want android-cts-... for some relevant version
AFAIK, the _rN suffix is the patchlevel
but I'm not super-expert at the AOSP tagging system, so YMMV
4:20 PM
Mark M.
it's also possible that the same error string is raised elsewhere in Android 5.x
I don't know of a way to search GitHub within a particular tagged edition of the source
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
which means that one of three things is happening:
1. that same message is raised elsewhere in Android 5.x
2. the problem is in some custom ROM (manufacturer or independent), or
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
It does not seem device specific
I looked into that.
I have one hypothesis
when I call this line List<MediaController> controllers = mediaSessionManager.getActiveSessions(notificationListener);
4:25 PM
sumeet-thadani
the notification listener being passed in is not yet started
onStartCommand calls the function which calls the offending line
do you think that matters>
Mark M.
enforceMediaPermissions() wouldn't seem to care about tht
er, that
but, I haven't traced through isEnabledNotificationListener(), which would be where that all comes from
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
so I'd be somewhat surprised if you got a substantial percentage of crashes that way
let me switch back to Rick, if he has another question, and I'll be back with you in a bit
Rick: your turn! do you have another question?
4:30 PM
Mark M.
Rick: if you come up with another question, let me know
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
are you working with the Uri of some media?
sumeet-thadani
Not really we just get notified when media starts on the device
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
all the time
and it works for 75% of users
so it's either a timing issue
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:)
4:35 PM
Rick R.
take care
4:35 PM
Mark M.
Rick: you too!
Rick R.
has left the room
Mark M.
what are you using for crash reporting?
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
I can check
Also, I came across this question on SO
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
wrap your call in a try/catch block, and fail gracefully
you could call checkPermission() on PackageManager to see if somebody ripped out the permission from the app and repackaged it
but, even if they did, there's nothing you can do to somehow add it back
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
How would that kill us
?
Mark M.
well, if the user has not yet enabled you as a notification listener, that would explain the symptoms
you could do the same check that the platform does (see isEnabledNotificationListener() in that MediaSessionService class) to see if you are indeed enabled
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
4:45 PM
Mark M.
BTW, if you have any other questions, go right ahead
4:50 PM
sumeet-thadani
I am just thinking things through
Mark M.
no worries
4:55 PM
sumeet-thadani
I am going to try a couple of things and see if we do better
Mark M.
OK
5:00 PM
Mark M.
well, that's a wrap for today's chat
the transcript will be posted to https://commonsware.com/office-hours/ shortly
the next chat is tomorrow at 9am US Eastern
have a pleasant day!
sumeet-thadani
has left the room
Mark M.
turned off guest access

Saturday, November 28

 

Office Hours

People in this transcript

  • Mark Murphy
  • Rick R
  • sumeet-thadani