Use NMS calculation of fixed importance

Rather than recalculating it again. Also align logic on
listing and details pages.

Test: NotificationBackendTest, NotificationPreferenceControllerTest
Bug: 231662091
Fixes: 231815850
Change-Id: If9572766666620008afb839ecb0828ace8d6073d
This commit is contained in:
Julia Reynolds
2022-05-10 16:42:37 -04:00
parent 23a85a1f96
commit 2011588b16
5 changed files with 35 additions and 120 deletions

View File

@@ -106,29 +106,20 @@ public class NotificationBackend {
return row;
}
public AppRow loadAppRow(Context context, PackageManager pm,
RoleManager roleManager, PackageInfo app) {
public AppRow loadAppRow(Context context, PackageManager pm, PackageInfo app) {
final AppRow row = loadAppRow(context, pm, app.applicationInfo);
recordCanBeBlocked(context, pm, roleManager, app, row);
recordCanBeBlocked(app, row);
return row;
}
void recordCanBeBlocked(Context context, PackageManager pm, RoleManager rm, PackageInfo app,
AppRow row) {
void recordCanBeBlocked(PackageInfo app, AppRow row) {
try {
row.systemApp = row.lockedImportance =
sINM.isPermissionFixed(app.packageName, row.userId);
sINM.isImportanceLocked(app.packageName, app.applicationInfo.uid);
} catch (RemoteException e) {
Log.w(TAG, "Error calling NMS", e);
}
// The permission system cannot make role permissions 'fixed', so check for these
// roles explicitly
List<String> roles = rm.getHeldRolesFromController(app.packageName);
if (roles.contains(RoleManager.ROLE_DIALER)
|| roles.contains(RoleManager.ROLE_EMERGENCY)) {
row.systemApp = row.lockedImportance = true;
}
// if the app targets T but has not requested the permission, we cannot change the
// permission state
if (app.applicationInfo.targetSdkVersion > Build.VERSION_CODES.S_V2) {
@@ -139,24 +130,6 @@ public class NotificationBackend {
}
}
@VisibleForTesting static void markAppRowWithBlockables(String[] nonBlockablePkgs, AppRow row,
String packageName) {
if (nonBlockablePkgs != null) {
int N = nonBlockablePkgs.length;
for (int i = 0; i < N; i++) {
String pkg = nonBlockablePkgs[i];
if (pkg == null) {
continue;
} else if (pkg.contains(":")) {
// handled by NotificationChannel.isImportanceLockedByOEM()
continue;
} else if (packageName.equals(nonBlockablePkgs[i])) {
row.systemApp = row.lockedImportance = true;
}
}
}
}
static public CharSequence getDeviceList(ICompanionDeviceManager cdm, LocalBluetoothManager lbm,
String pkg, int userId) {
boolean multiple = false;
@@ -191,10 +164,9 @@ public class NotificationBackend {
public boolean enableSwitch(Context context, ApplicationInfo app) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
app.packageName, PackageManager.GET_SIGNATURES);
RoleManager rm = context.getSystemService(RoleManager.class);
app.packageName, PackageManager.GET_PERMISSIONS);
final AppRow row = new AppRow();
recordCanBeBlocked(context, context.getPackageManager(), rm, info, row);
recordCanBeBlocked(info, row);
boolean systemBlockable = !row.systemApp || (row.systemApp && row.banned);
return systemBlockable && !row.lockedImportance;
} catch (PackageManager.NameNotFoundException e) {