Mark DataUsageState as nullable to avoid potential NPE risk

mDataUsageState is nullable in UnrestrictedDataAccessPreference.java, so we'd better
add a annotation to getDataUsageState(), and add a null-check before calling it.

Bug: 246828843

Test: manual and Robotest.
Change-Id: If7fea53ec7efd004391a09becdba5709ae686f40
This commit is contained in:
Shen Lin
2022-09-15 10:05:19 +08:00
parent 8b0e08ecee
commit eb627be0b4
2 changed files with 5 additions and 1 deletions

View File

@@ -194,7 +194,9 @@ public class UnrestrictedDataAccessPreferenceController extends BasePreferenceCo
logSpecialPermissionChange(allowlisted, accessPreference.getEntry().info.packageName);
mDataSaverBackend.setIsAllowlisted(accessPreference.getEntry().info.uid,
accessPreference.getEntry().info.packageName, allowlisted);
accessPreference.getDataUsageState().isDataSaverAllowlisted = allowlisted;
if (accessPreference.getDataUsageState() != null) {
accessPreference.getDataUsageState().isDataSaverAllowlisted = allowlisted;
}
return true;
}
return false;