Home | History | Annotate | Download | only in externalreceiver
      1 /*
      2  * Copyright (C) 2017 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.dialer.precall.externalreceiver;
     18 
     19 import android.app.Activity;
     20 import android.content.Context;
     21 import android.content.Intent;
     22 import android.os.Bundle;
     23 import android.support.annotation.Nullable;
     24 import android.telecom.PhoneAccountHandle;
     25 import android.telecom.TelecomManager;
     26 import com.android.dialer.callintent.CallInitiationType.Type;
     27 import com.android.dialer.callintent.CallIntentBuilder;
     28 import com.android.dialer.configprovider.ConfigProvider;
     29 import com.android.dialer.configprovider.ConfigProviderBindings;
     30 import com.android.dialer.logging.DialerImpression;
     31 import com.android.dialer.logging.Logger;
     32 import com.android.dialer.precall.PreCall;
     33 
     34 /**
     35  * Activity that forwards to {@link PreCall#start(Context, CallIntentBuilder)} so the pre-call flow
     36  * can be initiated by external apps. This activity is exported but can only be started by apps with
     37  * {@link android.Manifest.permission#CALL_PHONE}. Keyguard will be triggered if phone is locked.
     38  *
     39  * @see CallIntentBuilder
     40  */
     41 public class LaunchPreCallActivity extends Activity {
     42 
     43   public static final String ACTION_LAUNCH_PRE_CALL = "com.android.dialer.LAUNCH_PRE_CALL";
     44 
     45   public static final String EXTRA_PHONE_ACCOUNT_HANDLE = "phone_account_handle";
     46 
     47   public static final String EXTRA_IS_VIDEO_CALL = "is_video_call";
     48 
     49   public static final String EXTRA_CALL_SUBJECT = "call_subject";
     50 
     51   public static final String EXTRA_ALLOW_ASSISTED_DIAL = "allow_assisted_dial";
     52 
     53   @Override
     54   public void onCreate(@Nullable Bundle savedInstanceState) {
     55     super.onCreate(savedInstanceState);
     56     Logger.get(this).logImpression(DialerImpression.Type.PRECALL_INITIATED_EXTERNAL);
     57 
     58     ConfigProvider configProvider = ConfigProviderBindings.get(getApplicationContext());
     59     Intent intent = getIntent();
     60     CallIntentBuilder builder = new CallIntentBuilder(intent.getData(), Type.EXTERNAL_INITIATION);
     61 
     62     PhoneAccountHandle phoneAccountHandle = intent.getParcelableExtra(EXTRA_PHONE_ACCOUNT_HANDLE);
     63     if (phoneAccountHandle == null) {
     64       phoneAccountHandle = intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE);
     65     }
     66 
     67     builder
     68         .setPhoneAccountHandle(phoneAccountHandle)
     69         .setIsVideoCall(intent.getBooleanExtra(EXTRA_IS_VIDEO_CALL, false))
     70         .setCallSubject(intent.getStringExtra(EXTRA_CALL_SUBJECT))
     71         .setAllowAssistedDial(
     72             intent.getBooleanExtra(
     73                 EXTRA_ALLOW_ASSISTED_DIAL,
     74                 configProvider.getBoolean("assisted_dialing_default_precall_state", false)));
     75     PreCall.start(this, builder);
     76     finish();
     77   }
     78 }
     79