From 1127cfb00f88226d996d74e72e62ab506687b939 Mon Sep 17 00:00:00 2001 From: Steve Statia Date: Tue, 25 Mar 2025 11:38:31 -0700 Subject: [PATCH] Fix hidden menu not showing phone information 100% of the time when opening. The function that sends the special code is sending intents to all users, which is creating an activity for both the work profile and the system user. Whichever intent is received last will be the activity on top and displayed to the user, and since the work profile's hidden menu does not include the 'Phone information' option it creates this 'randomness' observed with opening the menu. This change ag/29101523 started sending the broadcast as UserHandle.ALL, instead of just from the current user causing the reception of more than one intent. This fix checks for the work profile and returns out of the function without starting another TestingSettings activity. Flag: EXEMPT bug fix Bug: 406016005 Test: manual test opening hidden menu, and opening after reboots (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:170fcaf31628d3faf689ce1b525bfba33052d877) Merged-In: I5a7937ba484afd3ba81c55e66bc53c217a778d18 Change-Id: I5a7937ba484afd3ba81c55e66bc53c217a778d18 --- .../TestingSettingsBroadcastReceiver.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/TestingSettingsBroadcastReceiver.java b/src/com/android/settings/TestingSettingsBroadcastReceiver.java index 9965630ea1b..f5bb1bb0167 100644 --- a/src/com/android/settings/TestingSettingsBroadcastReceiver.java +++ b/src/com/android/settings/TestingSettingsBroadcastReceiver.java @@ -20,12 +20,17 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Build; +import android.os.Process; +import android.os.UserHandle; +import android.os.UserManager; import android.telephony.TelephonyManager; +import android.util.Log; import com.android.settings.Settings.TestingSettingsActivity; public class TestingSettingsBroadcastReceiver extends BroadcastReceiver { + private final static String TAG = "TestingSettingsBroadcastReceiver"; public TestingSettingsBroadcastReceiver() { } @@ -35,10 +40,18 @@ public class TestingSettingsBroadcastReceiver extends BroadcastReceiver { if (intent != null && intent.getAction() != null && intent.getAction().equals(TelephonyManager.ACTION_SECRET_CODE) && !isDisabled(context)) { - Intent i = new Intent(Intent.ACTION_MAIN); - i.setClass(context, TestingSettingsActivity.class); - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(i); + UserManager userManager = context.getSystemService(UserManager.class); + UserHandle currentUser = Process.myUserHandle(); + if (userManager != null) { + if (userManager.getUserInfo(currentUser.hashCode()).isMain()) { + Intent i = new Intent(Intent.ACTION_MAIN); + i.setClass(context, TestingSettingsActivity.class); + i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(i); + } else { + Log.d(TAG, "Not main user, not starting TestingSettingsActivity."); + } + } } }