178a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad/* 278a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * Copyright (C) 2013 The Android Open Source Project 378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * 478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * Licensed under the Apache License, Version 2.0 (the "License"); 578a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * you may not use this file except in compliance with the License. 678a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * You may obtain a copy of the License at 778a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * 878a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * http://www.apache.org/licenses/LICENSE-2.0 978a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * 1078a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * Unless required by applicable law or agreed to in writing, software 1178a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * distributed under the License is distributed on an "AS IS" BASIS, 1278a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * See the License for the specific language governing permissions and 1478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * limitations under the License. 1578a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad */ 1678a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad 1778a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awadpackage com.android.server.telecom.components; 1878a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad 1978a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awadimport com.android.server.telecom.CallIntentProcessor; 208d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awadimport com.android.server.telecom.TelecomSystem; 2178a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad 2278a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awadimport android.app.Activity; 23b3feab5a6ad30161726cf2decf4c0b06a78f5d41Yorke Leeimport android.content.Context; 2478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awadimport android.content.Intent; 2578a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awadimport android.os.Bundle; 26b3feab5a6ad30161726cf2decf4c0b06a78f5d41Yorke Leeimport android.os.UserHandle; 27b3feab5a6ad30161726cf2decf4c0b06a78f5d41Yorke Leeimport android.os.UserManager; 28a3eccfee788c3ac3c831a443b085b141b39bb63dBrad Ebingerimport android.telecom.Log; 2978a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awadimport android.telecom.TelecomManager; 3078a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad 3178a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad// TODO: Needed for move to system service: import com.android.internal.R; 3278a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad 3378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad/** 3478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * Activity that handles system CALL actions and forwards them to {@link CallIntentProcessor}. 3578a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * Handles all three CALL action types: CALL, CALL_PRIVILEGED, and CALL_EMERGENCY. 3678a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * 3778a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * Pre-L, the only way apps were were allowed to make outgoing emergency calls was the 3878a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * ACTION_CALL_PRIVILEGED action (which requires the system only CALL_PRIVILEGED permission). 3978a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * 4078a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * In L, any app that has the CALL_PRIVILEGED permission can continue to make outgoing emergency 4178a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * calls via ACTION_CALL_PRIVILEGED. 4278a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * 4378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * In addition, the default dialer (identified via 4478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * {@link TelecomManager#getDefaultPhoneApp()} will also be granted the ability to 4578a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * make emergency outgoing calls using the CALL action. In order to do this, it must call 4678a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad * startActivityForResult on the CALL intent to allow its package name to be passed to 478d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awad * {@link UserCallActivity}. Calling startActivity will continue to work on all non-emergency 488d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awad * numbers just like it did pre-L. 4978a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad */ 508d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awadpublic class UserCallActivity extends Activity implements TelecomSystem.Component { 5178a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad 5278a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad @Override 5378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad protected void onCreate(Bundle bundle) { 5478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad super.onCreate(bundle); 5572930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger Log.startSession("UCA.oC"); 5672930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger try { 5772930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger // TODO: Figure out if there is something to restore from bundle. 5872930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger // See OutgoingCallBroadcaster in services/Telephony for more. 5972930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger Intent intent = getIntent(); 6072930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger verifyCallAction(intent); 6172930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger final UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE); 6272930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger final UserHandle userHandle = new UserHandle(userManager.getUserHandle()); 6372930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger // Once control flow has passed to this activity, it is no longer guaranteed that we can 6472930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger // accurately determine whether the calling package has the CALL_PHONE runtime permission. 6572930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger // At this point in time we trust that the ActivityManager has already performed this 6672930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger // validation before starting this activity. 67d307d6d02a5b3d8fb63e2af0c9ab5ae3ca16b201Tyler Gunn // Create a new instance of intent to avoid modifying the 68d307d6d02a5b3d8fb63e2af0c9ab5ae3ca16b201Tyler Gunn // ActivityThread.ActivityClientRecord#intent directly. 69d307d6d02a5b3d8fb63e2af0c9ab5ae3ca16b201Tyler Gunn // Modifying directly may be a potential risk when relaunching this activity. 70d307d6d02a5b3d8fb63e2af0c9ab5ae3ca16b201Tyler Gunn new UserCallIntentProcessor(this, userHandle).processIntent(new Intent(intent), 7172930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger getCallingPackage(), true /* hasCallAppOp*/); 7272930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger } finally { 7372930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger Log.endSession(); 7472930a80679d461ad694b6555b0749d5fc4e31a8Brad Ebinger } 7578a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad finish(); 7678a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad } 7778a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad 7878a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad private void verifyCallAction(Intent intent) { 7978a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad if (getClass().getName().equals(intent.getComponent().getClassName())) { 8078a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad // If we were launched directly from the CallActivity, not one of its more privileged 8178a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad // aliases, then make sure that only the non-privileged actions are allowed. 8278a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad if (!Intent.ACTION_CALL.equals(intent.getAction())) { 8378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad Log.w(this, "Attempt to deliver non-CALL action; forcing to CALL"); 8478a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad intent.setAction(Intent.ACTION_CALL); 8578a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad } 8678a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad } 8778a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad } 888d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awad 898d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awad @Override 908d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awad public TelecomSystem getTelecomSystem() { 918d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awad return TelecomSystem.getInstance(); 928d5d9ddc66b55b6906364ab3c0e244dab4d58f13Ihab Awad } 9378a5e6b9c1595c81f72d7a822617cb78db224e48Ihab Awad} 94