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