From 47eb3fe93e2dd4133fe1cc6b6c042dc1a2c84a6d Mon Sep 17 00:00:00 2001 From: Tyler Gunn Date: Mon, 12 Mar 2018 14:38:47 -0700 Subject: [PATCH] Add Telecom debug menu. New menu is accessible via *#*#828282#*#*. This is a developer settings type activity for the Telecom subsystem. Adding in an option to enable the enhanced call blocking functionality to facilitate testing. Test: Manual Bug: 28189985 Change-Id: If7ce957e3e04f8f3de2251bb70dafb6b5834a6d8 --- AndroidManifest.xml | 4 ++ res/layout/telecom_developer_menu.xml | 28 ++++++++++ res/values/strings.xml | 6 ++ .../server/telecom/DialerCodeReceiver.java | 11 ++++ .../server/telecom/SystemSettingsUtil.java | 10 ++++ .../android/server/telecom/TelecomSystem.java | 2 + .../telecom/settings/BlockedNumbersUtil.java | 4 +- .../telecom/ui/TelecomDeveloperMenu.java | 55 +++++++++++++++++++ 8 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 res/layout/telecom_developer_menu.xml create mode 100644 src/com/android/server/telecom/ui/TelecomDeveloperMenu.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 588e5c38e..9202e7412 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -288,6 +288,10 @@ + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index bb63ad2e0..8c29a21e0 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -285,4 +285,10 @@ Emergency call made Call Blocking has been disabled to allow emergency responders to contact you. + + Telecom Developer Menu + + Enhanced Call Blocking diff --git a/src/com/android/server/telecom/DialerCodeReceiver.java b/src/com/android/server/telecom/DialerCodeReceiver.java index 57f84a0ef..1cd922acb 100644 --- a/src/com/android/server/telecom/DialerCodeReceiver.java +++ b/src/com/android/server/telecom/DialerCodeReceiver.java @@ -19,9 +19,12 @@ package com.android.server.telecom; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.os.UserHandle; import android.telecom.Log; import android.telecom.TelecomManager; +import com.android.server.telecom.ui.TelecomDeveloperMenu; + /** * Receiver for "secret codes" broadcast by Dialer. */ @@ -38,6 +41,9 @@ public class DialerCodeReceiver extends BroadcastReceiver { // Writes a MARK to the Telecom log. public static final String TELECOM_SECRET_CODE_MARK = "826275"; + // Opens the Telecom developer menu. + public static final String TELECOM_SECRET_CODE_MENU = "828282"; + private final CallsManager mCallsManager; DialerCodeReceiver(CallsManager callsManager) { @@ -61,6 +67,11 @@ public class DialerCodeReceiver extends BroadcastReceiver { // add a non-call event. Call currentCall = mCallsManager.getActiveCall(); Log.addEvent(currentCall, LogUtils.Events.USER_LOG_MARK); + } else if (intent.getData().getHost().equals(TELECOM_SECRET_CODE_MENU)) { + Log.i("DialerCodeReceiver", "Secret code used to open developer menu."); + Intent confirmIntent = new Intent(context, TelecomDeveloperMenu.class); + confirmIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivityAsUser(confirmIntent, UserHandle.CURRENT); } } } diff --git a/src/com/android/server/telecom/SystemSettingsUtil.java b/src/com/android/server/telecom/SystemSettingsUtil.java index 3c75e4d73..97659a89f 100644 --- a/src/com/android/server/telecom/SystemSettingsUtil.java +++ b/src/com/android/server/telecom/SystemSettingsUtil.java @@ -36,4 +36,14 @@ public class SystemSettingsUtil { return Settings.System.getInt(context.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, 0) != 0; } + + public boolean isEnhancedCallBlockingEnabled(Context context) { + return Settings.System.getInt(context.getContentResolver(), + Settings.System.DEBUG_ENABLE_ENHANCED_CALL_BLOCKING, 0) != 0; + } + + public boolean setEnhancedCallBlockingEnabled(Context context, boolean enabled) { + return Settings.System.putInt(context.getContentResolver(), + Settings.System.DEBUG_ENABLE_ENHANCED_CALL_BLOCKING, enabled ? 1 : 0); + } } diff --git a/src/com/android/server/telecom/TelecomSystem.java b/src/com/android/server/telecom/TelecomSystem.java index 3fd0e2101..9ecdde2c5 100644 --- a/src/com/android/server/telecom/TelecomSystem.java +++ b/src/com/android/server/telecom/TelecomSystem.java @@ -96,6 +96,8 @@ public class TelecomSystem { .addDataAuthority(DialerCodeReceiver.TELECOM_SECRET_CODE_DEBUG_OFF, null); DIALER_SECRET_CODE_FILTER .addDataAuthority(DialerCodeReceiver.TELECOM_SECRET_CODE_MARK, null); + DIALER_SECRET_CODE_FILTER + .addDataAuthority(DialerCodeReceiver.TELECOM_SECRET_CODE_MENU, null); } private static TelecomSystem INSTANCE = null; diff --git a/src/com/android/server/telecom/settings/BlockedNumbersUtil.java b/src/com/android/server/telecom/settings/BlockedNumbersUtil.java index 4f45720cf..5acfe64f6 100644 --- a/src/com/android/server/telecom/settings/BlockedNumbersUtil.java +++ b/src/com/android/server/telecom/settings/BlockedNumbersUtil.java @@ -33,6 +33,7 @@ import android.text.TextDirectionHeuristics; import android.widget.Toast; import com.android.server.telecom.R; +import com.android.server.telecom.SystemSettingsUtil; import com.android.server.telecom.ui.NotificationChannelManager; import java.util.Locale; @@ -134,7 +135,8 @@ public final class BlockedNumbersUtil { carrierConfig = configManager.getDefaultConfig(); } return carrierConfig.getBoolean( - CarrierConfigManager.KEY_SUPPORT_ENHANCED_CALL_BLOCKING_BOOL); + CarrierConfigManager.KEY_SUPPORT_ENHANCED_CALL_BLOCKING_BOOL) + || new SystemSettingsUtil().isEnhancedCallBlockingEnabled(context); } /** diff --git a/src/com/android/server/telecom/ui/TelecomDeveloperMenu.java b/src/com/android/server/telecom/ui/TelecomDeveloperMenu.java new file mode 100644 index 000000000..ae2e8530a --- /dev/null +++ b/src/com/android/server/telecom/ui/TelecomDeveloperMenu.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.server.telecom.ui; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.Switch; + +import com.android.server.telecom.R; +import com.android.server.telecom.SystemSettingsUtil; + +/** + * Telecom Developer Settings Menu. + */ +public class TelecomDeveloperMenu extends Activity { + + private Switch mEnhancedCallingSwitch; + private SystemSettingsUtil mSystemSettingsUtil; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mSystemSettingsUtil = new SystemSettingsUtil(); + setContentView(R.layout.telecom_developer_menu); + + mEnhancedCallingSwitch = findViewById(R.id.switchEnhancedCallBlocking); + mEnhancedCallingSwitch.setOnClickListener(l -> { + handleEnhancedCallingToggle(); + }); + loadPreferences(); + } + + private void handleEnhancedCallingToggle() { + mSystemSettingsUtil.setEnhancedCallBlockingEnabled(this, + mEnhancedCallingSwitch.isChecked()); + } + + private void loadPreferences() { + mEnhancedCallingSwitch.setChecked(mSystemSettingsUtil.isEnhancedCallBlockingEnabled(this)); + } +} \ No newline at end of file