1 /* 2 * Copyright (C) 2013 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.server.telecom.components; 18 19 import com.android.server.telecom.CallIntentProcessor; 20 import com.android.server.telecom.TelecomSystem; 21 22 import android.app.Activity; 23 import android.content.Context; 24 import android.content.Intent; 25 import android.os.Bundle; 26 import android.os.UserHandle; 27 import android.os.UserManager; 28 import android.telecom.Log; 29 import android.telecom.TelecomManager; 30 31 // TODO: Needed for move to system service: import com.android.internal.R; 32 33 /** 34 * Activity that handles system CALL actions and forwards them to {@link CallIntentProcessor}. 35 * Handles all three CALL action types: CALL, CALL_PRIVILEGED, and CALL_EMERGENCY. 36 * 37 * Pre-L, the only way apps were were allowed to make outgoing emergency calls was the 38 * ACTION_CALL_PRIVILEGED action (which requires the system only CALL_PRIVILEGED permission). 39 * 40 * In L, any app that has the CALL_PRIVILEGED permission can continue to make outgoing emergency 41 * calls via ACTION_CALL_PRIVILEGED. 42 * 43 * In addition, the default dialer (identified via 44 * {@link TelecomManager#getDefaultPhoneApp()} will also be granted the ability to 45 * make emergency outgoing calls using the CALL action. In order to do this, it must call 46 * startActivityForResult on the CALL intent to allow its package name to be passed to 47 * {@link UserCallActivity}. Calling startActivity will continue to work on all non-emergency 48 * numbers just like it did pre-L. 49 */ 50 public class UserCallActivity extends Activity implements TelecomSystem.Component { 51 52 @Override onCreate(Bundle bundle)53 protected void onCreate(Bundle bundle) { 54 super.onCreate(bundle); 55 Log.startSession("UCA.oC"); 56 try { 57 // TODO: Figure out if there is something to restore from bundle. 58 // See OutgoingCallBroadcaster in services/Telephony for more. 59 Intent intent = getIntent(); 60 verifyCallAction(intent); 61 final UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE); 62 final UserHandle userHandle = new UserHandle(userManager.getUserHandle()); 63 // Once control flow has passed to this activity, it is no longer guaranteed that we can 64 // accurately determine whether the calling package has the CALL_PHONE runtime permission. 65 // At this point in time we trust that the ActivityManager has already performed this 66 // validation before starting this activity. 67 // Create a new instance of intent to avoid modifying the 68 // ActivityThread.ActivityClientRecord#intent directly. 69 // Modifying directly may be a potential risk when relaunching this activity. 70 new UserCallIntentProcessor(this, userHandle).processIntent(new Intent(intent), 71 getCallingPackage(), true /* hasCallAppOp*/); 72 } finally { 73 Log.endSession(); 74 } 75 finish(); 76 } 77 verifyCallAction(Intent intent)78 private void verifyCallAction(Intent intent) { 79 if (getClass().getName().equals(intent.getComponent().getClassName())) { 80 // If we were launched directly from the CallActivity, not one of its more privileged 81 // aliases, then make sure that only the non-privileged actions are allowed. 82 if (!Intent.ACTION_CALL.equals(intent.getAction())) { 83 Log.w(this, "Attempt to deliver non-CALL action; forcing to CALL"); 84 intent.setAction(Intent.ACTION_CALL); 85 } 86 } 87 } 88 89 @Override getTelecomSystem()90 public TelecomSystem getTelecomSystem() { 91 return TelecomSystem.getInstance(); 92 } 93 } 94