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