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