• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Log;
21 import com.android.server.telecom.TelecomSystem;
22 
23 import android.app.Activity;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.os.Bundle;
27 import android.os.UserHandle;
28 import android.os.UserManager;
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             new UserCallIntentProcessor(this, userHandle).processIntent(getIntent(),
68                     getCallingPackage(), true /* hasCallAppOp*/);
69         } finally {
70             Log.endSession();
71         }
72         finish();
73     }
74 
verifyCallAction(Intent intent)75     private void verifyCallAction(Intent intent) {
76         if (getClass().getName().equals(intent.getComponent().getClassName())) {
77             // If we were launched directly from the CallActivity, not one of its more privileged
78             // aliases, then make sure that only the non-privileged actions are allowed.
79             if (!Intent.ACTION_CALL.equals(intent.getAction())) {
80                 Log.w(this, "Attempt to deliver non-CALL action; forcing to CALL");
81                 intent.setAction(Intent.ACTION_CALL);
82             }
83         }
84     }
85 
86     @Override
getTelecomSystem()87     public TelecomSystem getTelecomSystem() {
88         return TelecomSystem.getInstance();
89     }
90 }
91