Files
packages_apps_Settings/src/com/android/settings/TestingSettingsBroadcastReceiver.java
Steve Statia 1127cfb00f 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
2025-04-01 20:42:13 -07:00

63 lines
2.3 KiB
Java

/*
* Copyright (C) 2021 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.settings;
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() {
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.getAction() != null
&& intent.getAction().equals(TelephonyManager.ACTION_SECRET_CODE)
&& !isDisabled(context)) {
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.");
}
}
}
}
private boolean isDisabled(Context context) {
return "user".equals(Build.TYPE) && context.getResources().getBoolean(
R.bool.config_hide_testing_settings_menu_for_user_builds);
}
}