1 /*
2  * Copyright (C) 2015 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;
18 
19 import android.content.BroadcastReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.os.UserHandle;
23 import android.telecom.Log;
24 import android.telecom.TelecomManager;
25 
26 import com.android.server.telecom.ui.TelecomDeveloperMenu;
27 
28 /**
29  * Receiver for "secret codes" broadcast by Dialer.
30  */
31 public class DialerCodeReceiver extends BroadcastReceiver {
32     // Copied from TelephonyIntents.java.
33     public static final String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE";
34 
35     // Enables extended logging for a period of time.
36     public static final String TELECOM_SECRET_CODE_DEBUG_ON = "823241";
37 
38     // Disables extended logging.
39     public static final String TELECOM_SECRET_CODE_DEBUG_OFF = "823240";
40 
41     // Writes a MARK to the Telecom log.
42     public static final String TELECOM_SECRET_CODE_MARK = "826275";
43 
44     // Opens the Telecom developer menu.
45     public static final String TELECOM_SECRET_CODE_MENU = "828282";
46 
47     private final CallsManager mCallsManager;
48 
DialerCodeReceiver(CallsManager callsManager)49     DialerCodeReceiver(CallsManager callsManager) {
50         mCallsManager = callsManager;
51     }
52 
53     @Override
onReceive(Context context, Intent intent)54     public void onReceive(Context context, Intent intent) {
55         if (SECRET_CODE_ACTION.equals(intent.getAction()) && intent.getData() != null &&
56                 intent.getData().getHost() != null) {
57             if (intent.getData().getHost().equals(TELECOM_SECRET_CODE_DEBUG_ON)) {
58                 Log.i("DialerCodeReceiver", "Secret code used to enable extended logging mode");
59                 Log.setIsExtendedLoggingEnabled(true);
60             } else if (intent.getData().getHost().equals(TELECOM_SECRET_CODE_DEBUG_OFF)) {
61                 Log.i("DialerCodeReceiver", "Secret code used to disable extended logging mode");
62                 Log.setIsExtendedLoggingEnabled(false);
63             } else if (intent.getData().getHost().equals(TELECOM_SECRET_CODE_MARK)) {
64                 Log.i("DialerCodeReceiver", "Secret code used to mark logs.");
65 
66                 // If there is an active call, add the "log mark" for that call; otherwise we will
67                 // add a non-call event.
68                 Call currentCall = mCallsManager.getActiveCall();
69                 Log.addEvent(currentCall, LogUtils.Events.USER_LOG_MARK);
70             } else if (intent.getData().getHost().equals(TELECOM_SECRET_CODE_MENU)) {
71                 Log.i("DialerCodeReceiver", "Secret code used to open developer menu.");
72                 Intent confirmIntent = new Intent(context, TelecomDeveloperMenu.class);
73                 confirmIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
74                 context.startActivityAsUser(confirmIntent, UserHandle.CURRENT);
75             }
76         }
77     }
78 }
79