• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, 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 package com.android.car.stream;
17 
18 import android.app.Application;
19 import android.content.Intent;
20 import android.util.Log;
21 import com.android.car.stream.media.MediaStreamProducer;
22 import com.android.car.stream.radio.RadioStreamProducer;
23 import com.android.car.stream.telecom.CurrentCallStreamProducer;
24 import com.android.car.stream.telecom.RecentCallStreamProducer;
25 
26 import java.util.ArrayList;
27 import java.util.List;
28 
29 /**
30  * Base application for {@link StreamService}
31  */
32 public class StreamApplication extends Application {
33     private static final String TAG = "StreamApplication";
34     private List<StreamProducer> streamProducers;
35 
36     @Override
onCreate()37     public void onCreate() {
38         // TODO(victorchan): start and bind stream service, then pass in bound instance to
39         // producers.
40         startService(new Intent(this, StreamService.class));
41 
42         super.onCreate();
43         if (Log.isLoggable(TAG, Log.DEBUG)) {
44             Log.d(TAG, "stream application started");
45         }
46         streamProducers = new ArrayList<>();
47         streamProducers.add(new CurrentCallStreamProducer(this /* context */));
48         streamProducers.add(new RecentCallStreamProducer(this /* context */));
49         streamProducers.add(new MediaStreamProducer(this /* context */));
50         streamProducers.add(new RadioStreamProducer(this /* context */));
51 
52         startProducers();
53     }
54 
55     @Override
onTerminate()56     public void onTerminate() {
57         if (Log.isLoggable(TAG, Log.DEBUG)) {
58             Log.d(TAG, "StreamApplication terminated");
59         }
60         super.onTerminate();
61         stopProducers();
62     }
63 
startProducers()64     private void startProducers() {
65         for (int i = 0; i < streamProducers.size(); i++) {
66             streamProducers.get(i).start();
67             if (Log.isLoggable(TAG, Log.DEBUG)) {
68                 Log.d(TAG, "Stream producers started: "
69                         + streamProducers.get(i).getClass().getName());
70             }
71         }
72     }
73 
stopProducers()74     private void stopProducers() {
75         for (int i = 0; i < streamProducers.size(); i++) {
76             streamProducers.get(i).stop();
77             if (Log.isLoggable(TAG, Log.DEBUG)) {
78                 Log.d(TAG, "Stream producers stopped: "
79                         + streamProducers.get(i).getClass().getName());
80             }
81         }
82     }
83 }
84