1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.car.carlauncher.homescreen.audio.media; 18 19 import android.content.Intent; 20 21 import com.android.car.carlauncher.homescreen.audio.IntentHandler; 22 23 /** 24 * Routes media {@link Intent} to {@link IntentHandler}. 25 */ 26 public class MediaIntentRouter { 27 private static MediaIntentRouter sInstance; 28 private IntentHandler mIntentHandler; 29 30 /** 31 * @return an instance of {@link MediaIntentRouter}. 32 */ getInstance()33 public static MediaIntentRouter getInstance() { 34 if (sInstance == null) { 35 sInstance = new MediaIntentRouter(); 36 } 37 return sInstance; 38 } 39 40 /** 41 * Register a {@link IntentHandler}. 42 */ registerMediaIntentHandler(IntentHandler intentHandler)43 public void registerMediaIntentHandler(IntentHandler intentHandler) { 44 mIntentHandler = intentHandler; 45 } 46 47 /** 48 * Dispatch a media intent to {@link IntentHandler} 49 */ handleMediaIntent(Intent intent)50 public void handleMediaIntent(Intent intent) { 51 if (intent != null) { 52 mIntentHandler.handleIntent(intent); 53 } 54 } 55 } 56