OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.media.ui; | 5 package org.chromium.chrome.browser.media.ui; |
6 | 6 |
7 import android.content.BroadcastReceiver; | 7 import android.content.BroadcastReceiver; |
8 import android.content.ComponentName; | 8 import android.content.ComponentName; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.Intent; | 10 import android.content.Intent; |
11 import android.content.pm.PackageManager; | 11 import android.content.pm.PackageManager; |
12 import android.content.pm.ResolveInfo; | 12 import android.content.pm.ResolveInfo; |
13 | 13 |
14 import java.util.List; | 14 import java.util.List; |
15 | 15 |
16 /** | 16 /** |
17 * MediaButtonReceiver is a basic BroadcastReceiver class that receives | 17 * MediaButtonReceiver is a basic BroadcastReceiver class that receives |
18 * ACTION_MEDIA_BUTTON from a MediaSessionCompat. It then forward these intents | 18 * ACTION_MEDIA_BUTTON from a MediaSessionCompat. It then forward these intents |
19 * to the service listening to them. | 19 * to the service listening to them. |
20 * This is there for backward compatibility with JB_MR0 and JB_MR1. | 20 * This is there for backward compatibility with JB_MR0 and JB_MR1. |
21 */ | 21 */ |
22 public class MediaButtonReceiver extends BroadcastReceiver { | 22 public abstract class MediaButtonReceiver extends BroadcastReceiver { |
23 private static final String LISTENER_SERVICE_CLASS_NAME = | 23 private static final String LISTENER_SERVICE_CLASS_NAME = |
24 "org.chromium.chrome.browser.media.ui" | 24 "org.chromium.chrome.browser.media.ui" |
25 + "MediaNotificationManager$ListenerService"; | 25 + "MediaNotificationManager$ListenerService"; |
| 26 public static final String EXTRA_NOTIFICATION_ID = |
| 27 "MediaNotificationManager.ListenerService.NOTIFICATION_ID"; |
| 28 |
| 29 public abstract int getNotificationId(); |
26 | 30 |
27 @Override | 31 @Override |
28 public void onReceive(Context context, Intent intent) { | 32 public void onReceive(Context context, Intent intent) { |
29 Intent queryIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); | 33 Intent queryIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); |
30 queryIntent.setPackage(context.getPackageName()); | 34 queryIntent.setPackage(context.getPackageName()); |
31 | 35 |
32 PackageManager pm = context.getPackageManager(); | 36 PackageManager pm = context.getPackageManager(); |
33 List<ResolveInfo> infos = pm.queryIntentServices(queryIntent, 0); | 37 List<ResolveInfo> infos = pm.queryIntentServices(queryIntent, 0); |
34 assert infos.size() == 1; | 38 assert infos.size() == 1; |
35 | 39 |
36 ResolveInfo info = infos.get(0); | 40 ResolveInfo info = infos.get(0); |
37 ComponentName component = new ComponentName(info.serviceInfo.packageName
, | 41 ComponentName component = new ComponentName(info.serviceInfo.packageName
, |
38 info.serviceInfo.name); | 42 info.serviceInfo.name); |
39 assert LISTENER_SERVICE_CLASS_NAME.equals(component.getClassName()); | 43 assert LISTENER_SERVICE_CLASS_NAME.equals(component.getClassName()); |
40 | 44 |
41 intent.setComponent(component); | 45 intent.setComponent(component); |
| 46 intent.putExtra(EXTRA_NOTIFICATION_ID, getNotificationId()); |
42 context.startService(intent); | 47 context.startService(intent); |
43 } | 48 } |
44 } | 49 } |
OLD | NEW |