Fix broken Safety Center redirect when SafetySourceData is null
Bug: b/373942609 Test: m & atest CellularSecurityPreferenceControllerTest Flag: EXEMPT bugfix Change-Id: I2373ccb5cb51bca23815db9f7645efccc3e0cd88
This commit is contained in:
@@ -23,6 +23,7 @@ import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.safetycenter.SafetyCenterManager;
|
||||
import android.safetycenter.SafetySourceData;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
@@ -48,6 +49,7 @@ import java.util.List;
|
||||
public class CellularSecurityPreferenceController extends BasePreferenceController {
|
||||
|
||||
private static final String LOG_TAG = "CellularSecurityPreferenceController";
|
||||
private static final String SAFETY_SOURCE_ID = "AndroidCellularNetworkSecurity";
|
||||
|
||||
private @Nullable TelephonyManager mTelephonyManager;
|
||||
|
||||
@@ -134,13 +136,30 @@ public class CellularSecurityPreferenceController extends BasePreferenceControll
|
||||
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||
return super.handlePreferenceTreeClick(preference);
|
||||
}
|
||||
boolean isSafetyCenterSupported = isSafetyCenterSupported();
|
||||
if (isSafetyCenterSupported && areNotificationsEnabled()) {
|
||||
if (!isSafetyCenterSupported()) {
|
||||
// Realistically, it's unlikely to end up in handlePreferenceTreeClick with SafetyCenter
|
||||
// being not supported on the device.
|
||||
return false;
|
||||
}
|
||||
// Need to check that both Safety Center is available on device, and also that the HALs are
|
||||
// enabled before showing the Safety Center UI. Otherwise, we need to take them to the page
|
||||
// where the HALs can be enabled.
|
||||
SafetyCenterManager safetyCenterManager = mContext.getSystemService(
|
||||
SafetyCenterManager.class);
|
||||
SafetySourceData data = null;
|
||||
if (safetyCenterManager.isSafetyCenterEnabled()) {
|
||||
data = safetyCenterManager.getSafetySourceData(SAFETY_SOURCE_ID);
|
||||
}
|
||||
// Can only redirect to SafetyCenter if it has received data via the SafetySource, as
|
||||
// SafetyCenter doesn't support redirecting to a specific page associated with a source
|
||||
// if it hasn't received data from that source. See b/373942609 for details.
|
||||
if (data != null && areNotificationsEnabled()) {
|
||||
Intent safetyCenterIntent = new Intent(Intent.ACTION_SAFETY_CENTER);
|
||||
safetyCenterIntent.putExtra(SafetyCenterManager.EXTRA_SAFETY_SOURCES_GROUP_ID,
|
||||
"AndroidCellularNetworkSecuritySources");
|
||||
mContext.startActivity(safetyCenterIntent);
|
||||
} else {
|
||||
Log.v(LOG_TAG, "Hardware APIs not enabled, or data source is null.");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(CellularSecuritySettingsFragment.KEY_CELLULAR_SECURITY_PREFERENCE, "");
|
||||
|
||||
|
Reference in New Issue
Block a user