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:
@@ -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) {
|
||||
|
@@ -24,6 +24,7 @@ import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -171,7 +172,8 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
|
||||
return overrideCanConfigureValue;
|
||||
}
|
||||
if (mAppRow != null) {
|
||||
return !mAppRow.systemApp && !mAppRow.lockedImportance;
|
||||
boolean systemBlockable = !mAppRow.systemApp || (mAppRow.systemApp && mAppRow.banned);
|
||||
return systemBlockable && !mAppRow.lockedImportance;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@@ -25,7 +25,6 @@ import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.role.RoleManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -69,7 +68,6 @@ abstract public class NotificationSettings extends DashboardFragment {
|
||||
protected PackageManager mPm;
|
||||
protected NotificationBackend mBackend = new NotificationBackend();
|
||||
protected NotificationManager mNm;
|
||||
protected RoleManager mRm;
|
||||
protected Context mContext;
|
||||
|
||||
protected int mUid;
|
||||
@@ -116,7 +114,6 @@ abstract public class NotificationSettings extends DashboardFragment {
|
||||
|
||||
mPm = getPackageManager();
|
||||
mNm = NotificationManager.from(mContext);
|
||||
mRm = mContext.getSystemService(RoleManager.class);
|
||||
|
||||
mPkg = mArgs != null && mArgs.containsKey(AppInfoBase.ARG_PACKAGE_NAME)
|
||||
? mArgs.getString(AppInfoBase.ARG_PACKAGE_NAME)
|
||||
@@ -290,7 +287,7 @@ abstract public class NotificationSettings extends DashboardFragment {
|
||||
}
|
||||
|
||||
private void loadAppRow() {
|
||||
mAppRow = mBackend.loadAppRow(mContext, mPm, mRm, mPkgInfo);
|
||||
mAppRow = mBackend.loadAppRow(mContext, mPm, mPkgInfo);
|
||||
}
|
||||
|
||||
private void loadChannelGroup() {
|
||||
|
Reference in New Issue
Block a user