Home | History | Annotate | Download | only in incallui
      1 /*
      2  * Copyright (C) 2014 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.incallui;
     18 
     19 import android.content.Context;
     20 import android.content.Intent;
     21 import android.os.IBinder;
     22 import android.telecom.Call;
     23 import android.telecom.CallAudioState;
     24 import android.telecom.InCallService;
     25 import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler;
     26 import com.android.incallui.audiomode.AudioModeProvider;
     27 import com.android.incallui.call.CallList;
     28 import com.android.incallui.call.ExternalCallList;
     29 import com.android.incallui.call.TelecomAdapter;
     30 
     31 /**
     32  * Used to receive updates about calls from the Telecom component. This service is bound to Telecom
     33  * while there exist calls which potentially require UI. This includes ringing (incoming), dialing
     34  * (outgoing), and active calls. When the last call is disconnected, Telecom will unbind to the
     35  * service triggering InCallActivity (via CallList) to finish soon after.
     36  */
     37 public class InCallServiceImpl extends InCallService {
     38 
     39   @Override
     40   public void onCallAudioStateChanged(CallAudioState audioState) {
     41     AudioModeProvider.getInstance().onAudioStateChanged(audioState);
     42   }
     43 
     44   @Override
     45   public void onBringToForeground(boolean showDialpad) {
     46     InCallPresenter.getInstance().onBringToForeground(showDialpad);
     47   }
     48 
     49   @Override
     50   public void onCallAdded(Call call) {
     51     InCallPresenter.getInstance().onCallAdded(call);
     52   }
     53 
     54   @Override
     55   public void onCallRemoved(Call call) {
     56     InCallPresenter.getInstance().onCallRemoved(call);
     57   }
     58 
     59   @Override
     60   public void onCanAddCallChanged(boolean canAddCall) {
     61     InCallPresenter.getInstance().onCanAddCallChanged(canAddCall);
     62   }
     63 
     64   @Override
     65   public IBinder onBind(Intent intent) {
     66     final Context context = getApplicationContext();
     67     final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context);
     68     InCallPresenter.getInstance()
     69         .setUp(
     70             context,
     71             CallList.getInstance(),
     72             new ExternalCallList(),
     73             new StatusBarNotifier(context, contactInfoCache),
     74             new ExternalCallNotifier(context, contactInfoCache),
     75             contactInfoCache,
     76             new ProximitySensor(
     77                 context, AudioModeProvider.getInstance(), new AccelerometerListener(context)),
     78             new FilteredNumberAsyncQueryHandler(context));
     79     InCallPresenter.getInstance().onServiceBind();
     80     InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
     81     TelecomAdapter.getInstance().setInCallService(this);
     82 
     83     return super.onBind(intent);
     84   }
     85 
     86   @Override
     87   public boolean onUnbind(Intent intent) {
     88     super.onUnbind(intent);
     89 
     90     InCallPresenter.getInstance().onServiceUnbind();
     91     tearDown();
     92 
     93     return false;
     94   }
     95 
     96   private void tearDown() {
     97     Log.v(this, "tearDown");
     98     // Tear down the InCall system
     99     TelecomAdapter.getInstance().clearInCallService();
    100     InCallPresenter.getInstance().tearDown();
    101   }
    102 }
    103