Merge "Fix visibility and editability of importance fields" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7c802e553f
@@ -54,13 +54,7 @@ public class BlockPreferenceController extends NotificationPreferenceController
|
||||
if (mAppRow == null) {
|
||||
return false;
|
||||
}
|
||||
if (mChannel != null) {
|
||||
return isChannelBlockable();
|
||||
} else if (mChannelGroup != null) {
|
||||
return isChannelGroupBlockable();
|
||||
} else {
|
||||
return !mAppRow.systemApp || (mAppRow.systemApp && mAppRow.banned);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateState(Preference preference) {
|
||||
@@ -78,6 +72,19 @@ public class BlockPreferenceController extends NotificationPreferenceController
|
||||
}
|
||||
bar.setDisabledByAdmin(mAdmin);
|
||||
|
||||
if (mChannel != null && !isChannelBlockable()) {
|
||||
bar.setEnabled(false);
|
||||
}
|
||||
|
||||
if (mChannelGroup != null && !isChannelGroupBlockable()) {
|
||||
bar.setEnabled(false);
|
||||
}
|
||||
|
||||
if (mChannel == null && mAppRow.systemApp
|
||||
&& (!mAppRow.banned || mAppRow.lockedImportance)) {
|
||||
bar.setEnabled(false);
|
||||
}
|
||||
|
||||
if (mChannel != null) {
|
||||
bar.setChecked(!mAppRow.banned
|
||||
&& mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
|
||||
|
@@ -62,7 +62,7 @@ public class HighImportancePreferenceController extends NotificationPreferenceCo
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (mAppRow != null && mChannel != null) {
|
||||
preference.setEnabled(mAdmin == null && isChannelBlockable());
|
||||
preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
|
||||
|
||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||
pref.setChecked(mChannel.getImportance() >= IMPORTANCE_HIGH);
|
||||
|
@@ -59,9 +59,9 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (mAppRow!= null && mChannel != null) {
|
||||
preference.setEnabled(mAdmin == null && isChannelBlockable());
|
||||
preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
|
||||
ImportancePreference pref = (ImportancePreference) preference;
|
||||
pref.setConfigurable(isChannelBlockable());
|
||||
pref.setConfigurable(!mChannel.isImportanceLockedByOEM());
|
||||
pref.setImportance(mChannel.getImportance());
|
||||
pref.setDisplayInStatusBar(mBackend.showSilentInStatusBar(mContext.getPackageName()));
|
||||
// TODO: b/128445911 pass along lock screen setting
|
||||
|
@@ -62,7 +62,7 @@ public class MinImportancePreferenceController extends NotificationPreferenceCon
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (mAppRow != null && mChannel != null) {
|
||||
preference.setEnabled(mAdmin == null && isChannelBlockable());
|
||||
preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
|
||||
|
||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||
pref.setChecked(mChannel.getImportance() == IMPORTANCE_MIN);
|
||||
|
@@ -21,6 +21,7 @@ import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
|
||||
import android.app.INotificationManager;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.app.role.RoleManager;
|
||||
import android.app.usage.IUsageStatsManager;
|
||||
import android.app.usage.UsageEvents;
|
||||
import android.content.ComponentName;
|
||||
@@ -86,14 +87,22 @@ public class NotificationBackend {
|
||||
return !systemApp || (systemApp && blocked);
|
||||
}
|
||||
|
||||
public AppRow loadAppRow(Context context, PackageManager pm, PackageInfo app) {
|
||||
public AppRow loadAppRow(Context context, PackageManager pm,
|
||||
RoleManager roleManager, PackageInfo app) {
|
||||
final AppRow row = loadAppRow(context, pm, app.applicationInfo);
|
||||
recordCanBeBlocked(context, pm, app, row);
|
||||
recordCanBeBlocked(context, pm, roleManager, app, row);
|
||||
return row;
|
||||
}
|
||||
|
||||
void recordCanBeBlocked(Context context, PackageManager pm, PackageInfo app, AppRow row) {
|
||||
void recordCanBeBlocked(Context context, PackageManager pm, RoleManager rm, PackageInfo app,
|
||||
AppRow row) {
|
||||
row.systemApp = Utils.isSystemPackage(context.getResources(), pm, app);
|
||||
List<String> roles = rm.getHeldRolesFromController(app.packageName);
|
||||
if (roles.contains(RoleManager.ROLE_SMS)
|
||||
|| roles.contains(RoleManager.ROLE_DIALER)
|
||||
|| roles.contains(RoleManager.ROLE_EMERGENCY)) {
|
||||
row.systemApp = true;
|
||||
}
|
||||
final String[] nonBlockablePkgs = context.getResources().getStringArray(
|
||||
com.android.internal.R.array.config_nonBlockableNotificationPackages);
|
||||
markAppRowWithBlockables(nonBlockablePkgs, row, app.packageName);
|
||||
@@ -108,10 +117,8 @@ public class NotificationBackend {
|
||||
if (pkg == null) {
|
||||
continue;
|
||||
} else if (pkg.contains(":")) {
|
||||
// Interpret as channel; lock only this channel for this app.
|
||||
if (packageName.equals(pkg.split(":", 2)[0])) {
|
||||
row.lockedChannelId = pkg.split(":", 2 )[1];
|
||||
}
|
||||
// handled by NotificationChannel.isImportanceLockedByOEM()
|
||||
continue;
|
||||
} else if (packageName.equals(nonBlockablePkgs[i])) {
|
||||
row.systemApp = row.lockedImportance = true;
|
||||
}
|
||||
@@ -123,8 +130,9 @@ public class NotificationBackend {
|
||||
try {
|
||||
PackageInfo info = context.getPackageManager().getPackageInfo(
|
||||
app.packageName, PackageManager.GET_SIGNATURES);
|
||||
RoleManager rm = context.getSystemService(RoleManager.class);
|
||||
final AppRow row = new AppRow();
|
||||
recordCanBeBlocked(context, context.getPackageManager(), info, row);
|
||||
recordCanBeBlocked(context, context.getPackageManager(), rm, info, row);
|
||||
return row.systemApp;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
@@ -491,7 +499,6 @@ public class NotificationBackend {
|
||||
public boolean first; // first app in section
|
||||
public boolean systemApp;
|
||||
public boolean lockedImportance;
|
||||
public String lockedChannelId;
|
||||
public boolean showBadge;
|
||||
public boolean allowBubbles;
|
||||
public int userId;
|
||||
|
@@ -110,27 +110,13 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isChannelConfigurable() {
|
||||
if (mAppRow != null && mAppRow.lockedImportance) {
|
||||
return false;
|
||||
}
|
||||
if (mChannel != null && mAppRow != null) {
|
||||
return !Objects.equals(mChannel.getId(), mAppRow.lockedChannelId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isChannelBlockable() {
|
||||
if (mChannel != null && mAppRow != null) {
|
||||
if (!isChannelConfigurable()) {
|
||||
if (mChannel.isImportanceLockedByCriticalDeviceFunction()
|
||||
|| mChannel.isImportanceLockedByOEM()) {
|
||||
return mChannel.getImportance() == IMPORTANCE_NONE;
|
||||
}
|
||||
|
||||
if (mChannel.isImportanceLockedByOEM()
|
||||
|| mChannel.isImportanceLockedByCriticalDeviceFunction()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return mChannel.isBlockableSystem() || !mAppRow.systemApp
|
||||
|| mChannel.getImportance() == IMPORTANCE_NONE;
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ 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;
|
||||
@@ -36,7 +37,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.BlendMode;
|
||||
import android.graphics.BlendModeColorFilter;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
@@ -71,6 +71,7 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
||||
protected PackageManager mPm;
|
||||
protected NotificationBackend mBackend = new NotificationBackend();
|
||||
protected NotificationManager mNm;
|
||||
protected RoleManager mRm;
|
||||
protected Context mContext;
|
||||
|
||||
protected int mUid;
|
||||
@@ -101,6 +102,7 @@ abstract public class NotificationSettingsBase 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)
|
||||
@@ -195,7 +197,7 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
||||
}
|
||||
|
||||
private void loadAppRow() {
|
||||
mAppRow = mBackend.loadAppRow(mContext, mPm, mPkgInfo);
|
||||
mAppRow = mBackend.loadAppRow(mContext, mPm, mRm, mPkgInfo);
|
||||
}
|
||||
|
||||
private void loadChannelGroup() {
|
||||
@@ -342,7 +344,7 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
||||
|
||||
protected boolean isChannelConfigurable(NotificationChannel channel) {
|
||||
if (channel != null && mAppRow != null) {
|
||||
return !channel.getId().equals(mAppRow.lockedChannelId);
|
||||
return !channel.isImportanceLockedByOEM();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -353,6 +355,14 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (channel.isImportanceLockedByCriticalDeviceFunction()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (channel.isImportanceLockedByOEM()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return channel.isBlockableSystem()
|
||||
|| channel.getImportance() == NotificationManager.IMPORTANCE_NONE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user