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   private ReturnToCallController returnToCallController;
     40 
     41   @Override
     42   public void onCallAudioStateChanged(CallAudioState audioState) {
     43     AudioModeProvider.getInstance().onAudioStateChanged(audioState);
     44   }
     45 
     46   @Override
     47   public void onBringToForeground(boolean showDialpad) {
     48     InCallPresenter.getInstance().onBringToForeground(showDialpad);
     49   }
     50 
     51   @Override
     52   public void onCallAdded(Call call) {
     53     InCallPresenter.getInstance().onCallAdded(call);
     54   }
     55 
     56   @Override
     57   public void onCallRemoved(Call call) {
     58     InCallPresenter.getInstance().onCallRemoved(call);
     59   }
     60 
     61   @Override
     62   public void onCanAddCallChanged(boolean canAddCall) {
     63     InCallPresenter.getInstance().onCanAddCallChanged(canAddCall);
     64   }
     65 
     66   @Override
     67   public IBinder onBind(Intent intent) {
     68     final Context context = getApplicationContext();
     69     final ContactInfoCache contactInfoCache = ContactInfoCache.getInstance(context);
     70     InCallPresenter.getInstance()
     71         .setUp(
     72             context,
     73             CallList.getInstance(),
     74             new ExternalCallList(),
     75             new StatusBarNotifier(context, contactInfoCache),
     76             new ExternalCallNotifier(context, contactInfoCache),
     77             contactInfoCache,
     78             new ProximitySensor(
     79                 context, AudioModeProvider.getInstance(), new AccelerometerListener(context)),
     80             new FilteredNumberAsyncQueryHandler(context));
     81     InCallPresenter.getInstance().onServiceBind();
     82     InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
     83     TelecomAdapter.getInstance().setInCallService(this);
     84     if (ReturnToCallController.isEnabled(this)) {
     85       returnToCallController = new ReturnToCallController(this);
     86     }
     87 
     88     return super.onBind(intent);
     89   }
     90 
     91   @Override
     92   public boolean onUnbind(Intent intent) {
     93     super.onUnbind(intent);
     94 
     95     InCallPresenter.getInstance().onServiceUnbind();
     96     tearDown();
     97 
     98     return false;
     99   }
    100 
    101   private void tearDown() {
    102     Log.v(this, "tearDown");
    103     // Tear down the InCall system
    104     TelecomAdapter.getInstance().clearInCallService();
    105     InCallPresenter.getInstance().tearDown();
    106     if (returnToCallController != null) {
    107       returnToCallController.tearDown();
    108       returnToCallController = null;
    109     }
    110   }
    111 }
    112