Snap for 8989391 from 3b0cbefac1 to udc-release

Change-Id: I1f17186b207f23abd24a6e129c644cf44547b969
This commit is contained in:
Android Build Coastguard Worker
2022-08-25 01:26:21 +00:00
48 changed files with 525 additions and 441 deletions

View File

@@ -74,12 +74,12 @@ public class BluetoothBroadcastDialog extends InstrumentedDialogFragment {
TextView title = layout.findViewById(com.android.settingslib.R.id.dialog_title);
TextView subTitle = layout.findViewById(com.android.settingslib.R.id.dialog_subtitle);
title.setText(mContext.getString(R.string.bluetooth_broadcast_dialog_title));
subTitle.setText(
mContext.getString(R.string.bluetooth_broadcast_dialog_broadcast_message));
Button broadcastBtn = layout.findViewById(com.android.settingslib.R.id.positive_btn);
if (isBroadcastSupported() && mIsMediaStreaming) {
title.setText(mContext.getString(R.string.bluetooth_broadcast_dialog_title));
subTitle.setText(
mContext.getString(R.string.bluetooth_broadcast_dialog_broadcast_message));
broadcastBtn.setVisibility(View.VISIBLE);
if (TextUtils.isEmpty(mCurrentAppLabel)) {
broadcastBtn.setText(mContext.getString(R.string.bluetooth_broadcast_dialog_title));
@@ -92,6 +92,9 @@ public class BluetoothBroadcastDialog extends InstrumentedDialogFragment {
launchMediaOutputBroadcastDialog();
});
} else {
title.setText(mContext.getString(R.string.bluetooth_find_broadcast));
subTitle.setText(
mContext.getString(R.string.bluetooth_broadcast_dialog_find_message));
broadcastBtn.setVisibility(View.GONE);
}

View File

@@ -42,14 +42,12 @@ public class DreamComplicationPreferenceController extends TogglePreferenceContr
@Override
public boolean isChecked() {
return mBackend.getEnabledComplications().containsAll(mBackend.getSupportedComplications());
return mBackend.getComplicationsEnabled();
}
@Override
public boolean setChecked(boolean isChecked) {
for (int complication : mBackend.getSupportedComplications()) {
mBackend.setComplicationEnabled(complication, isChecked);
}
mBackend.setComplicationsEnabled(isChecked);
return true;
}

View File

@@ -31,7 +31,6 @@ import com.android.settings.fuelgauge.batterytip.detectors.SmartBatteryDetector;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.fuelgauge.EstimateKt;
import com.android.settingslib.utils.AsyncLoaderCompat;
@@ -67,16 +66,14 @@ public class BatteryTipLoader extends AsyncLoaderCompat<List<BatteryTip>> {
final BatteryTipPolicy policy = new BatteryTipPolicy(getContext());
final BatteryInfo batteryInfo = mBatteryUtils.getBatteryInfo(TAG);
final Context context = getContext();
final boolean extraDefend = FeatureFactory.getFactory(context)
.getPowerUsageFeatureProvider(context)
.isExtraDefend();
tips.add(new LowBatteryDetector(context, policy, batteryInfo).detect());
tips.add(new HighUsageDetector(context, policy, mBatteryUsageStats, batteryInfo).detect());
tips.add(new SmartBatteryDetector(
context, policy, batteryInfo, context.getContentResolver()).detect());
tips.add(new EarlyWarningDetector(policy, context).detect());
tips.add(new BatteryDefenderDetector(batteryInfo, extraDefend).detect());
tips.add(new BatteryDefenderDetector(
batteryInfo, context.getApplicationContext()).detect());
Collections.sort(tips);
return tips;
}

View File

@@ -16,28 +16,33 @@
package com.android.settings.fuelgauge.batterytip.detectors;
import android.content.Context;
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.batterytip.tips.BatteryDefenderTip;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.overlay.FeatureFactory;
/**
* Detect whether the battery is overheated
*/
public class BatteryDefenderDetector implements BatteryTipDetector {
private final BatteryInfo mBatteryInfo;
private final boolean mExtraDefend;
private final Context mContext;
public BatteryDefenderDetector(BatteryInfo batteryInfo, boolean extraDefend) {
public BatteryDefenderDetector(BatteryInfo batteryInfo, Context context) {
mBatteryInfo = batteryInfo;
mExtraDefend = extraDefend;
mContext = context;
}
@Override
public BatteryTip detect() {
final int state =
mBatteryInfo.isOverheated
? BatteryTip.StateType.NEW
: BatteryTip.StateType.INVISIBLE;
return new BatteryDefenderTip(state, mExtraDefend);
if (mBatteryInfo.isOverheated) {
final boolean extraDefend = FeatureFactory.getFactory(mContext)
.getPowerUsageFeatureProvider(mContext)
.isExtraDefend();
return new BatteryDefenderTip(BatteryTip.StateType.NEW, extraDefend);
}
return new BatteryDefenderTip(BatteryTip.StateType.INVISIBLE);
}
}

View File

@@ -108,7 +108,7 @@ public class BatteryDefenderTip extends BatteryTip {
});
cardPreference.setPrimaryButtonVisible(isPluggedIn(context));
cardPreference.setSecondaryButtonText(context.getString(R.string.see_more));
cardPreference.setSecondaryButtonText(context.getString(R.string.learn_more));
cardPreference.setSecondaryButtonClickListener(unused -> cardPreference.performClick());
cardPreference.setSecondaryButtonVisible(true);
}

View File

@@ -51,7 +51,7 @@ public class AppBubbleListPreferenceController extends AppConversationListPrefer
private static final String KEY = "bubble_conversations";
public AppBubbleListPreferenceController(Context context, NotificationBackend backend) {
super(context, backend, KEY);
super(context, backend);
}
@Override
@@ -80,25 +80,25 @@ public class AppBubbleListPreferenceController extends AppConversationListPrefer
}
@Override
public int getAvailabilityStatus() {
public boolean isAvailable() {
// copy rather than inherit super's isAvailable because apps can link to this page
// as part of onboarding, before they send a valid conversation notification
if (mAppRow == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mAppRow.banned) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mChannel != null) {
if (mBackend.onlyHasDefaultChannel(mAppRow.pkg, mAppRow.uid)
|| NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
}
if (mAppRow.bubblePreference == BUBBLE_PREFERENCE_NONE) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
return AVAILABLE;
return true;
}
@VisibleForTesting

View File

@@ -32,7 +32,7 @@ public class AddToHomeScreenPreferenceController extends NotificationPreferenceC
private static final String KEY = "add_to_home";
public AddToHomeScreenPreferenceController(Context context, NotificationBackend backend) {
super(context, backend, KEY);
super(context, backend);
}
@Override
@@ -41,11 +41,11 @@ public class AddToHomeScreenPreferenceController extends NotificationPreferenceC
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
return mConversationInfo != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
return mConversationInfo != null;
}
@Override

View File

@@ -40,7 +40,7 @@ public class AllowSoundPreferenceController extends NotificationPreferenceContro
public AllowSoundPreferenceController(Context context,
NotificationSettings.DependentFieldListener dependentFieldListener,
NotificationBackend backend) {
super(context, backend, KEY_IMPORTANCE);
super(context, backend);
mDependentFieldListener = dependentFieldListener;
}
@@ -50,14 +50,11 @@ public class AllowSoundPreferenceController extends NotificationPreferenceContro
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mChannel != null && NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) {
return AVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
return mChannel != null && NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId());
}

View File

@@ -64,7 +64,7 @@ public class AppChannelsBypassingDndPreferenceController extends NotificationPre
public AppChannelsBypassingDndPreferenceController(
Context context,
NotificationBackend backend) {
super(context, backend, KEY);
super(context, backend);
}
@Override
@@ -110,8 +110,8 @@ public class AppChannelsBypassingDndPreferenceController extends NotificationPre
}
@Override
public int getAvailabilityStatus() {
return mAppRow != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
return mAppRow != null;
}
@Override

View File

@@ -49,12 +49,7 @@ public class AppConversationListPreferenceController extends NotificationPrefere
protected PreferenceCategory mPreference;
public AppConversationListPreferenceController(Context context, NotificationBackend backend) {
this(context, backend, KEY);
}
public AppConversationListPreferenceController(Context context, NotificationBackend backend,
String key) {
super(context, backend, key);
super(context, backend);
}
@Override
@@ -63,24 +58,21 @@ public class AppConversationListPreferenceController extends NotificationPrefere
}
@Override
public int getAvailabilityStatus() {
public boolean isAvailable() {
if (mAppRow == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mAppRow.banned) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mChannel != null) {
if (mBackend.onlyHasDefaultChannel(mAppRow.pkg, mAppRow.uid)
|| NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
}
if (mBackend.hasSentValidMsg(mAppRow.pkg, mAppRow.uid) || mBackend.isInInvalidMsgState(
mAppRow.pkg, mAppRow.uid)) {
return AVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
return mBackend.hasSentValidMsg(mAppRow.pkg, mAppRow.uid) || mBackend.isInInvalidMsgState(
mAppRow.pkg, mAppRow.uid);
}
@Override

View File

@@ -32,7 +32,7 @@ public class AppLinkPreferenceController extends NotificationPreferenceControlle
private static final String KEY_APP_LINK = "app_link";
public AppLinkPreferenceController(Context context) {
super(context, null, KEY_APP_LINK);
super(context, null);
}
@Override
@@ -41,11 +41,11 @@ public class AppLinkPreferenceController extends NotificationPreferenceControlle
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
return mAppRow.settingsIntent != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
return mAppRow.settingsIntent != null;
}
@Override

View File

@@ -38,7 +38,7 @@ public class BadgePreferenceController extends NotificationPreferenceController
public BadgePreferenceController(Context context,
NotificationBackend backend) {
super(context, backend, KEY_BADGE);
super(context, backend);
}
@Override
@@ -47,29 +47,25 @@ public class BadgePreferenceController extends NotificationPreferenceController
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mAppRow == null && mChannel == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (Settings.Secure.getInt(mContext.getContentResolver(),
NOTIFICATION_BADGING, SYSTEM_WIDE_ON) == SYSTEM_WIDE_OFF) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mChannel != null) {
if (isDefaultChannel()) {
return AVAILABLE;
return true;
} else {
return mAppRow == null
? CONDITIONALLY_UNAVAILABLE
: mAppRow.showBadge
? AVAILABLE
: CONDITIONALLY_UNAVAILABLE;
return mAppRow == null ? false : mAppRow.showBadge;
}
}
return AVAILABLE;
return true;
}
@Override

View File

@@ -42,7 +42,7 @@ public class BlockPreferenceController extends NotificationPreferenceController
public BlockPreferenceController(Context context,
NotificationSettings.DependentFieldListener dependentFieldListener,
NotificationBackend backend) {
super(context, backend, KEY_BLOCK);
super(context, backend);
mDependentFieldListener = dependentFieldListener;
}
@@ -52,14 +52,14 @@ public class BlockPreferenceController extends NotificationPreferenceController
}
@Override
public int getAvailabilityStatus() {
public boolean isAvailable() {
if (mAppRow == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mPreferenceFilter != null && !isIncludedInFilter()) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
return AVAILABLE;
return true;
}
@Override

View File

@@ -32,15 +32,15 @@ public class BubbleCategoryPreferenceController extends NotificationPreferenceCo
static final int ON = 1;
public BubbleCategoryPreferenceController(Context context) {
super(context, null, KEY);
super(context, null);
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
return areBubblesEnabled() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
return areBubblesEnabled();
}
@Override

View File

@@ -32,15 +32,15 @@ public class BubbleLinkPreferenceController extends NotificationPreferenceContro
static final int ON = 1;
public BubbleLinkPreferenceController(Context context) {
super(context, null, KEY);
super(context, null);
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
return areBubblesEnabled() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
return areBubblesEnabled();
}
@Override

View File

@@ -56,7 +56,7 @@ public class BubblePreferenceController extends NotificationPreferenceController
public BubblePreferenceController(Context context, @Nullable FragmentManager fragmentManager,
NotificationBackend backend, boolean isAppPage,
@Nullable NotificationSettings.DependentFieldListener listener) {
super(context, backend, KEY);
super(context, backend);
mFragmentManager = fragmentManager;
mIsAppPage = isAppPage;
mListener = listener;
@@ -68,24 +68,21 @@ public class BubblePreferenceController extends NotificationPreferenceController
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (!mIsAppPage && !isEnabled()) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mChannel != null) {
if (isDefaultChannel()) {
return AVAILABLE;
return true;
} else {
if (mAppRow != null && mAppRow.bubblePreference != BUBBLE_PREFERENCE_NONE) {
return AVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
return mAppRow != null && mAppRow.bubblePreference != BUBBLE_PREFERENCE_NONE;
}
}
return AVAILABLE;
return true;
}
@Override

View File

@@ -42,31 +42,28 @@ public class BubbleSummaryPreferenceController extends NotificationPreferenceCon
static final int ON = 1;
public BubbleSummaryPreferenceController(Context context, NotificationBackend backend) {
super(context, backend, KEY);
super(context, backend);
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mAppRow == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mChannel != null) {
if (!isGloballyEnabled()) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (isDefaultChannel()) {
return AVAILABLE;
return true;
} else {
return mAppRow != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
return mAppRow != null;
}
}
if (isGloballyEnabled() && mBackend.hasSentValidBubble(mAppRow.pkg, mAppRow.uid)) {
return AVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
return isGloballyEnabled() && mBackend.hasSentValidBubble(mAppRow.pkg, mAppRow.uid);
}
@Override

View File

@@ -28,7 +28,6 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Slog;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -40,19 +39,16 @@ import androidx.preference.SwitchPreference;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.PrimarySwitchPreference;
import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ChannelListPreferenceController extends NotificationPreferenceController
implements BasePreferenceController.UiBlocker {
public class ChannelListPreferenceController extends NotificationPreferenceController {
private static final String KEY = "channels";
private static final String KEY_GENERAL_CATEGORY = "categories";
@@ -63,7 +59,7 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
private PreferenceCategory mPreference;
public ChannelListPreferenceController(Context context, NotificationBackend backend) {
super(context, backend, KEY);
super(context, backend);
}
@Override
@@ -72,20 +68,20 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
}
@Override
public int getAvailabilityStatus() {
public boolean isAvailable() {
if (mAppRow == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mAppRow.banned) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mChannel != null) {
if (mBackend.onlyHasDefaultChannel(mAppRow.pkg, mAppRow.uid)
|| NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
}
return AVAILABLE;
return true;
}
@Override
@@ -95,17 +91,24 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
@Override
public void updateState(Preference preference) {
mPreference = (PreferenceCategory) preference;
// Load channel settings
ThreadUtils.postOnBackgroundThread(() -> {
mPreference = (PreferenceCategory) preference;
// Load channel settings
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... unused) {
mChannelGroupList = mBackend.getGroups(mAppRow.pkg, mAppRow.uid).getList();
Collections.sort(mChannelGroupList, CHANNEL_GROUP_COMPARATOR);
ThreadUtils.getUiThreadHandler().getLooper().prepare();
return null;
}
@Override
protected void onPostExecute(Void unused) {
if (mContext == null) {
return;
}
updateFullList(mPreference, mChannelGroupList);
ThreadUtils.postOnMainThread(() -> {
showPreferences();
});
});
}
}.execute();
}
/**
@@ -141,12 +144,6 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
}
}
private void showPreferences() {
if (mUiBlockListener != null) {
mUiBlockListener.onBlockerWorkFinished(this);
}
}
/**
* Looks for the category for the given group's key at the expected index, if that doesn't
* match, it checks all groups, and if it can't find that group anywhere, it creates it.

View File

@@ -37,7 +37,7 @@ public class ConversationDemotePreferenceController extends NotificationPreferen
public ConversationDemotePreferenceController(Context context,
SettingsPreferenceFragment hostFragment,
NotificationBackend backend) {
super(context, backend, KEY);
super(context, backend);
mHostFragment = hostFragment;
}
@@ -47,17 +47,14 @@ public class ConversationDemotePreferenceController extends NotificationPreferen
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mAppRow == null || mChannel == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (!TextUtils.isEmpty(mChannel.getConversationId()) && !mChannel.isDemoted()) {
return AVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
return !TextUtils.isEmpty(mChannel.getConversationId()) && !mChannel.isDemoted();
}
@Override

View File

@@ -45,7 +45,7 @@ public class ConversationHeaderPreferenceController extends NotificationPreferen
private boolean mStarted = false;
public ConversationHeaderPreferenceController(Context context, DashboardFragment fragment) {
super(context, null, PREF_KEY_APP_HEADER);
super(context, null);
mFragment = fragment;
}
@@ -55,8 +55,8 @@ public class ConversationHeaderPreferenceController extends NotificationPreferen
}
@Override
public int getAvailabilityStatus() {
return mAppRow != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
return mAppRow != null;
}
@Override

View File

@@ -34,7 +34,7 @@ public class ConversationPriorityPreferenceController extends NotificationPrefer
public ConversationPriorityPreferenceController(Context context,
NotificationBackend backend, NotificationSettings.DependentFieldListener listener) {
super(context, backend, KEY);
super(context, backend);
mDependentFieldListener = listener;
}
@@ -44,14 +44,14 @@ public class ConversationPriorityPreferenceController extends NotificationPrefer
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mAppRow == null || mChannel == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
return AVAILABLE;
return true;
}
@Override

View File

@@ -37,7 +37,7 @@ public class ConversationPromotePreferenceController extends NotificationPrefere
public ConversationPromotePreferenceController(Context context,
SettingsPreferenceFragment hostFragment,
NotificationBackend backend) {
super(context, backend, KEY);
super(context, backend);
mHostFragment = hostFragment;
}
@@ -47,17 +47,14 @@ public class ConversationPromotePreferenceController extends NotificationPrefere
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mAppRow == null || mChannel == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (!TextUtils.isEmpty(mChannel.getConversationId()) && mChannel.isDemoted()) {
return AVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
return !TextUtils.isEmpty(mChannel.getConversationId()) && mChannel.isDemoted();
}
@Override

View File

@@ -30,7 +30,7 @@ public class DeletedChannelsPreferenceController extends NotificationPreferenceC
private static final String KEY_DELETED = "deleted";
public DeletedChannelsPreferenceController(Context context, NotificationBackend backend) {
super(context, backend, KEY_DELETED);
super(context, backend);
}
@Override
@@ -39,19 +39,16 @@ public class DeletedChannelsPreferenceController extends NotificationPreferenceC
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
// only visible on app screen
if (mChannel != null || hasValidGroup()) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid) > 0) {
return AVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
return mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid) > 0;
}
@Override

View File

@@ -29,7 +29,7 @@ public class DescriptionPreferenceController extends NotificationPreferenceContr
private static final String KEY_DESC = "desc";
public DescriptionPreferenceController(Context context) {
super(context, null, KEY_DESC);
super(context, null);
}
@Override
@@ -38,20 +38,20 @@ public class DescriptionPreferenceController extends NotificationPreferenceContr
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mChannel == null && !hasValidGroup()) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mChannel != null && !TextUtils.isEmpty(mChannel.getDescription())) {
return AVAILABLE;
return true;
}
if (hasValidGroup() && !TextUtils.isEmpty(mChannelGroup.getDescription())) {
return AVAILABLE;
return true;
}
return CONDITIONALLY_UNAVAILABLE;
return false;
}
@Override

View File

@@ -31,7 +31,7 @@ public class DndPreferenceController extends NotificationPreferenceController
private static final String KEY_BYPASS_DND = "bypass_dnd";
public DndPreferenceController(Context context, NotificationBackend backend) {
super(context, backend, KEY_BYPASS_DND);
super(context, backend);
}
@Override
@@ -40,11 +40,11 @@ public class DndPreferenceController extends NotificationPreferenceController
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE || mChannel == null) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable() || mChannel == null) {
return false;
}
return AVAILABLE;
return true;
}
@Override

View File

@@ -45,7 +45,7 @@ public class HeaderPreferenceController extends NotificationPreferenceController
private boolean mStarted = false;
public HeaderPreferenceController(Context context, DashboardFragment fragment) {
super(context, null, PREF_KEY_APP_HEADER);
super(context, null);
mFragment = fragment;
}
@@ -55,8 +55,8 @@ public class HeaderPreferenceController extends NotificationPreferenceController
}
@Override
public int getAvailabilityStatus() {
return mAppRow != null ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
return mAppRow != null;
}
@Override

View File

@@ -37,7 +37,7 @@ public class HighImportancePreferenceController extends NotificationPreferenceCo
public HighImportancePreferenceController(Context context,
NotificationSettings.DependentFieldListener dependentFieldListener,
NotificationBackend backend) {
super(context, backend, KEY_IMPORTANCE);
super(context, backend);
mDependentFieldListener = dependentFieldListener;
}
@@ -47,19 +47,17 @@ public class HighImportancePreferenceController extends NotificationPreferenceCo
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mChannel == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (isDefaultChannel()) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
return mChannel.getImportance() >= IMPORTANCE_DEFAULT
? AVAILABLE
: CONDITIONALLY_UNAVAILABLE;
return mChannel.getImportance() >= IMPORTANCE_DEFAULT;
}
@Override

View File

@@ -38,7 +38,7 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
public ImportancePreferenceController(Context context,
NotificationSettings.DependentFieldListener dependentFieldListener,
NotificationBackend backend) {
super(context, backend, KEY_IMPORTANCE);
super(context, backend);
mDependentFieldListener = dependentFieldListener;
}
@@ -48,14 +48,14 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mChannel == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
return !isDefaultChannel() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
return !isDefaultChannel();
}
@Override

View File

@@ -31,7 +31,7 @@ public class InvalidConversationInfoPreferenceController extends NotificationPre
public InvalidConversationInfoPreferenceController(Context context,
NotificationBackend backend) {
super(context, backend, KEY);
super(context, backend);
}
@Override
@@ -40,19 +40,17 @@ public class InvalidConversationInfoPreferenceController extends NotificationPre
}
@Override
public int getAvailabilityStatus() {
public boolean isAvailable() {
if (mAppRow == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mAppRow.banned) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mPreferenceFilter != null && !isIncludedInFilter()) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid)
? AVAILABLE
: CONDITIONALLY_UNAVAILABLE;
return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
}
@Override

View File

@@ -31,7 +31,7 @@ public class InvalidConversationPreferenceController extends NotificationPrefere
private static final String KEY = "invalid_conversation_switch";
public InvalidConversationPreferenceController(Context context, NotificationBackend backend) {
super(context, backend, KEY);
super(context, backend);
}
@Override
@@ -40,19 +40,17 @@ public class InvalidConversationPreferenceController extends NotificationPrefere
}
@Override
public int getAvailabilityStatus() {
public boolean isAvailable() {
if (mAppRow == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mAppRow.banned) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mPreferenceFilter != null && !isIncludedInFilter()) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid)
? AVAILABLE
: CONDITIONALLY_UNAVAILABLE;
return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
}
@Override

View File

@@ -33,7 +33,7 @@ public class LightsPreferenceController extends NotificationPreferenceController
private static final String KEY_LIGHTS = "lights";
public LightsPreferenceController(Context context, NotificationBackend backend) {
super(context, backend, KEY_LIGHTS);
super(context, backend);
}
@Override
@@ -42,18 +42,16 @@ public class LightsPreferenceController extends NotificationPreferenceController
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mChannel == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && canPulseLight()
&& !isDefaultChannel()) {
return AVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
&& canPulseLight()
&& !isDefaultChannel();
}
@Override

View File

@@ -37,7 +37,7 @@ public class MinImportancePreferenceController extends NotificationPreferenceCon
public MinImportancePreferenceController(Context context,
NotificationSettings.DependentFieldListener dependentFieldListener,
NotificationBackend backend) {
super(context, backend, KEY_IMPORTANCE);
super(context, backend);
mDependentFieldListener = dependentFieldListener;
}
@@ -47,17 +47,17 @@ public class MinImportancePreferenceController extends NotificationPreferenceCon
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mChannel == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (isDefaultChannel()) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
return mChannel.getImportance() <= IMPORTANCE_LOW ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
return mChannel.getImportance() <= IMPORTANCE_LOW;
}
@Override

View File

@@ -17,24 +17,26 @@
package com.android.settings.notification.app;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.os.UserHandle.USER_SYSTEM;
import android.annotation.Nullable;
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;
import android.os.UserManager;
import android.provider.Settings;
import android.util.Log;
import android.util.Slog;
import androidx.preference.Preference;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.Comparator;
import java.util.List;
@@ -44,7 +46,7 @@ import java.util.Objects;
* Parent class for preferences appearing on notification setting pages at the app,
* notification channel group, or notification channel level.
*/
public abstract class NotificationPreferenceController extends BasePreferenceController {
public abstract class NotificationPreferenceController extends AbstractPreferenceController {
private static final String TAG = "ChannelPrefContr";
@Nullable
protected NotificationChannel mChannel;
@@ -69,11 +71,8 @@ public abstract class NotificationPreferenceController extends BasePreferenceCon
boolean overrideCanBlockValue;
boolean overrideCanConfigureValue;
boolean mLoadedChannelState;
public NotificationPreferenceController(Context context, NotificationBackend backend,
String key) {
super(context, key);
public NotificationPreferenceController(Context context, NotificationBackend backend) {
super(context);
mContext = context;
mNm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
mBackend = backend;
@@ -82,30 +81,28 @@ public abstract class NotificationPreferenceController extends BasePreferenceCon
}
/**
* Returns available if field's parent object is not blocked.
* Returns true if field's parent object is not blocked.
*/
@Override
public int getAvailabilityStatus() {
public boolean isAvailable() {
if (mAppRow == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mAppRow.banned) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mChannelGroup != null) {
if (mChannelGroup.isBlocked()) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
}
if (mChannel != null) {
if (mPreferenceFilter != null && !isIncludedInFilter()) {
return CONDITIONALLY_UNAVAILABLE;
}
if(mChannel.getImportance() == IMPORTANCE_NONE) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
return mChannel.getImportance() != IMPORTANCE_NONE;
}
return AVAILABLE;
return true;
}
protected void onResume(NotificationBackend.AppRow appRow,

View File

@@ -41,7 +41,6 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.util.Slog;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
@@ -130,52 +129,15 @@ abstract public class NotificationSettings extends DashboardFragment {
}
}
mUserId = UserHandle.getUserId(mUid);
mPkgInfo = findPackageInfo(mPkg, mUid);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mIntent == null && mArgs == null) {
toastAndFinish("no intent");
return;
}
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
toastAndFinish("Missing package or uid or packageinfo");
return;
}
startListeningToPackageRemove();
}
@Override
public void onDestroy() {
stopListeningToPackageRemove();
super.onDestroy();
}
@Override
public void onResume() {
super.onResume();
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
toastAndFinish("Missing package or uid or packageinfo");
return;
}
mPkgInfo = findPackageInfo(mPkg, mUid);
if (mPkgInfo != null) {
mUserId = UserHandle.getUserId(mUid);
mSuspendedAppsAdmin = RestrictedLockUtilsInternal.checkIfApplicationIsSuspended(
mContext, mPkg, mUserId);
loadAppRow();
if (mAppRow == null) {
toastAndFinish("Can't load package");
return;
}
loadChannel();
loadConversation();
loadAppRow();
loadChannelGroup();
loadPreferencesFilter();
collectConfigActivities();
@@ -195,6 +157,55 @@ abstract public class NotificationSettings extends DashboardFragment {
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mIntent == null && mArgs == null) {
Log.w(TAG, "No intent");
toastAndFinish();
return;
}
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) {
Log.w(TAG, "Missing package or uid or packageinfo");
toastAndFinish();
return;
}
startListeningToPackageRemove();
}
@Override
public void onDestroy() {
stopListeningToPackageRemove();
super.onDestroy();
}
@Override
public void onResume() {
super.onResume();
if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null || mAppRow == null) {
Log.w(TAG, "Missing package or uid or packageinfo");
finish();
return;
}
// Reload app, channel, etc onResume in case they've changed. A little wasteful if we've
// just done onAttach but better than making every preference controller reload all
// the data
loadAppRow();
if (mAppRow == null) {
Log.w(TAG, "Can't load package");
finish();
return;
}
loadChannel();
loadConversation();
loadChannelGroup();
loadPreferencesFilter();
collectConfigActivities();
}
protected void animatePanel() {
if (mPreferenceFilter != null) {
mLayoutView = getActivity().findViewById(R.id.main_content);
@@ -296,8 +307,7 @@ abstract public class NotificationSettings extends DashboardFragment {
}
}
protected void toastAndFinish(String msg) {
Log.w(TAG, msg);
protected void toastAndFinish() {
Toast.makeText(mContext, R.string.app_not_found_dlg_text, Toast.LENGTH_SHORT).show();
getActivity().finish();
}

View File

@@ -30,7 +30,7 @@ public class NotificationsOffPreferenceController extends NotificationPreference
private static final String KEY_BLOCKED_DESC = "block_desc";
public NotificationsOffPreferenceController(Context context) {
super(context, null, KEY_BLOCKED_DESC);
super(context, null);
}
@Override
@@ -39,20 +39,16 @@ public class NotificationsOffPreferenceController extends NotificationPreference
}
@Override
public int getAvailabilityStatus() {
public boolean isAvailable() {
if (mAppRow == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (mPreferenceFilter != null && !isIncludedInFilter()) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
// Available only when other controllers are unavailable - this UI replaces the UI that
// would give more detailed notification controls.
if (super.getAvailabilityStatus() == AVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
} else {
return AVAILABLE;
}
return !super.isAvailable();
}
@Override

View File

@@ -47,7 +47,7 @@ public class SoundPreferenceController extends NotificationPreferenceController
public SoundPreferenceController(Context context, SettingsPreferenceFragment hostFragment,
NotificationSettings.DependentFieldListener dependentFieldListener,
NotificationBackend backend) {
super(context, backend, KEY_SOUND);
super(context, backend);
mFragment = hostFragment;
mListener = dependentFieldListener;
}
@@ -58,17 +58,14 @@ public class SoundPreferenceController extends NotificationPreferenceController
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mChannel == null) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && !isDefaultChannel()) {
return AVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && !isDefaultChannel();
}
@Override

View File

@@ -34,7 +34,7 @@ public class VibrationPreferenceController extends NotificationPreferenceControl
private final Vibrator mVibrator;
public VibrationPreferenceController(Context context, NotificationBackend backend) {
super(context, backend, KEY_VIBRATE);
super(context, backend);
mVibrator = context.getSystemService(Vibrator.class);
}
@@ -44,15 +44,14 @@ public class VibrationPreferenceController extends NotificationPreferenceControl
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE || mChannel == null) {
return CONDITIONALLY_UNAVAILABLE;
}
if (checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && !isDefaultChannel()
&& mVibrator != null && mVibrator.hasVibrator()) {
return AVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable() || mChannel == null) {
return false;
}
return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
&& !isDefaultChannel()
&& mVibrator != null
&& mVibrator.hasVibrator();
}
@Override

View File

@@ -48,7 +48,7 @@ public class VisibilityPreferenceController extends NotificationPreferenceContro
public VisibilityPreferenceController(Context context, LockPatternUtils utils,
NotificationBackend backend) {
super(context, backend, KEY_VISIBILITY_OVERRIDE);
super(context, backend);
mLockPatternUtils = utils;
}
@@ -58,18 +58,14 @@ public class VisibilityPreferenceController extends NotificationPreferenceContro
}
@Override
public int getAvailabilityStatus() {
if (super.getAvailabilityStatus() == CONDITIONALLY_UNAVAILABLE) {
return CONDITIONALLY_UNAVAILABLE;
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mChannel == null || mAppRow.banned) {
return CONDITIONALLY_UNAVAILABLE;
return false;
}
if (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && isLockScreenSecure()) {
return AVAILABLE;
}
return CONDITIONALLY_UNAVAILABLE;
return checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && isLockScreenSecure();
}
@Override

View File

@@ -65,6 +65,8 @@ public class SimDialogActivity extends FragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SimDialogProhibitService.supportDismiss(this);
getWindow().addSystemFlags(
WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
showOrUpdateDialog();
@@ -225,4 +227,15 @@ public class SimDialogActivity extends FragmentActivity {
}
return null;
}
/*
* Force dismiss this Activity.
*/
protected void forceClose() {
if (isFinishing() || isDestroyed()) {
return;
}
Log.d(TAG, "Dismissed by Service");
finishAndRemoveTask();
}
}

View File

@@ -0,0 +1,89 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.sim;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import java.lang.ref.WeakReference;
import java.util.concurrent.RejectedExecutionException;
/**
* A class for routing dismiss dialog request to SimDialogActivity.
*/
public class SimDialogProhibitService {
private static final String TAG = "SimDialogProhibitService";
private static WeakReference<SimDialogActivity> sSimDialogActivity;
/**
* Support the dismiss of {@link SimDialogActivity} (singletone.)
*
* @param activity {@link SimDialogActivity}
*/
public static void supportDismiss(SimDialogActivity activity) {
sSimDialogActivity = new WeakReference<SimDialogActivity>(activity);
}
/**
* Dismiss SimDialogActivity dialog.
*
* @param context is a {@link Context}
*/
public static void dismissDialog(Context context) {
// Dismiss existing dialog.
if (!dismissDialogThroughRunnable()) {
dismissDialogThroughIntent(context);
}
}
/**
* Dismiss dialog (if there's any).
*
* @return {@code true} when success, {@code false} when failure.
*/
protected static boolean dismissDialogThroughRunnable() {
final SimDialogActivity activity = (sSimDialogActivity == null) ?
null : sSimDialogActivity.get();
if (activity == null) {
Log.i(TAG, "No SimDialogActivity for dismiss.");
return true;
}
try {
activity.getMainExecutor().execute(() -> activity.forceClose());
return true;
} catch (RejectedExecutionException exception) {
Log.w(TAG, "Fail to close SimDialogActivity through executor", exception);
}
return false;
}
/**
* Dismiss dialog through {@link Intent}.
*
* @param uiContext is {@link Context} for start SimDialogActivity.
*/
protected static void dismissDialogThroughIntent(Context uiContext) {
Intent newIntent = new Intent(uiContext, SimDialogActivity.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
newIntent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.PICK_DISMISS);
uiContext.startActivity(newIntent);
}
}

View File

@@ -164,10 +164,7 @@ public class SimSelectNotification extends BroadcastReceiver {
// If the dialog type is to dismiss.
if (dialogType == EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS) {
Intent newIntent = new Intent(context, SimDialogActivity.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
newIntent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, PICK_DISMISS);
context.startActivity(newIntent);
SimDialogProhibitService.dismissDialog(context);
return;
}

View File

@@ -24,7 +24,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.UserManager;
import android.provider.Settings;
import android.util.FeatureFlagUtils;
import android.util.Log;
import androidx.appcompat.app.AlertDialog;
@@ -87,9 +86,7 @@ public class RemoveGuestOnExitPreferenceController extends BasePreferenceControl
|| !UserManager.isGuestUserAllowEphemeralStateChange()
|| !mUserCaps.isAdmin()
|| mUserCaps.disallowAddUser()
|| mUserCaps.disallowAddUserSetByAdmin()
|| !FeatureFlagUtils.isEnabled(mContext,
FeatureFlagUtils.SETTINGS_GUEST_MODE_UX_CHANGES)) {
|| mUserCaps.disallowAddUserSetByAdmin()) {
return DISABLED_FOR_USER;
} else {
return mUserCaps.mUserSwitcherEnabled ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;

View File

@@ -49,7 +49,6 @@ import android.os.UserManager;
import android.provider.ContactsContract;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;
import android.util.Log;
import android.util.SparseArray;
import android.view.Gravity;
@@ -490,11 +489,6 @@ public class UserSettings extends SettingsPreferenceFragment
updateUserList();
}
private boolean isEnableGuestModeUxChanges() {
return FeatureFlagUtils.isEnabled(getContext(),
FeatureFlagUtils.SETTINGS_GUEST_MODE_UX_CHANGES);
}
/**
* Loads profile information for the current user.
*/
@@ -1362,33 +1356,25 @@ public class UserSettings extends SettingsPreferenceFragment
}
mGuestCategory.setVisible(true);
mGuestExitPreference.setVisible(true);
if (isEnableGuestModeUxChanges()) {
mGuestResetPreference.setVisible(true);
mGuestResetPreference.setVisible(true);
boolean isGuestFirstLogin = Settings.Secure.getIntForUser(
getContext().getContentResolver(),
SETTING_GUEST_HAS_LOGGED_IN,
0,
UserHandle.myUserId()) <= 1;
String guestExitSummary;
if (mUserCaps.mIsEphemeral) {
guestExitSummary = getContext().getString(
R.string.guest_notification_ephemeral);
} else if (isGuestFirstLogin) {
guestExitSummary = getContext().getString(
R.string.guest_notification_non_ephemeral);
} else {
guestExitSummary = getContext().getString(
R.string.guest_notification_non_ephemeral_non_first_login);
}
mGuestExitPreference.setSummary(guestExitSummary);
boolean isGuestFirstLogin = Settings.Secure.getIntForUser(
getContext().getContentResolver(),
SETTING_GUEST_HAS_LOGGED_IN,
0,
UserHandle.myUserId()) <= 1;
String guestExitSummary;
if (mUserCaps.mIsEphemeral) {
guestExitSummary = getContext().getString(
R.string.guest_notification_ephemeral);
} else if (isGuestFirstLogin) {
guestExitSummary = getContext().getString(
R.string.guest_notification_non_ephemeral);
} else {
mGuestExitPreference.setIcon(getEncircledDefaultIcon());
mGuestExitPreference.setTitle(
mGuestUserAutoCreated
? com.android.settingslib.R.string.guest_reset_guest
: com.android.settingslib.R.string.guest_exit_guest);
guestExitSummary = getContext().getString(
R.string.guest_notification_non_ephemeral_non_first_login);
}
mGuestExitPreference.setSummary(guestExitSummary);
}
private void updateGuestCategory(Context context, List<UserInfo> users) {
@@ -1417,16 +1403,12 @@ public class UserSettings extends SettingsPreferenceFragment
pref.setOnPreferenceClickListener(this);
pref.setEnabled(canOpenUserDetails);
pref.setSelectable(true);
if (isEnableGuestModeUxChanges()) {
Drawable icon = getContext().getDrawable(R.drawable.ic_account_circle_outline);
icon.setTint(
getColorAttrDefaultColor(getContext(), android.R.attr.colorControlNormal));
pref.setIcon(encircleUserIcon(
UserIcons.convertToBitmapAtUserIconSize(
getContext().getResources(), icon)));
} else {
pref.setIcon(getEncircledDefaultIcon());
}
Drawable icon = getContext().getDrawable(R.drawable.ic_account_circle_outline);
icon.setTint(
getColorAttrDefaultColor(getContext(), android.R.attr.colorControlNormal));
pref.setIcon(encircleUserIcon(
UserIcons.convertToBitmapAtUserIconSize(
getContext().getResources(), icon)));
pref.setKey(KEY_USER_GUEST);
pref.setOrder(Preference.DEFAULT_ORDER);
if (mUserCaps.mDisallowSwitchUser) {
@@ -1468,13 +1450,6 @@ public class UserSettings extends SettingsPreferenceFragment
&& mUserCaps.mUserSwitcherEnabled) {
isVisible = true;
mAddGuest.setVisible(true);
// when isEnableGuestModeUxChanges() is true, the icon is set via the layout xml
// In com.android.settings.users.UserSettingsTest
// we disable the check for setIcon being called
if (!isEnableGuestModeUxChanges()) {
Drawable icon = context.getDrawable(R.drawable.ic_account_circle);
mAddGuest.setIcon(centerAndTint(icon));
}
mAddGuest.setSelectable(true);
if (mGuestUserAutoCreated && mGuestCreationScheduled.get()) {
mAddGuest.setTitle(com.android.internal.R.string.guest_name);
@@ -1492,21 +1467,11 @@ public class UserSettings extends SettingsPreferenceFragment
private void updateAddUser(Context context) {
updateAddUserCommon(context, mAddUser, mUserCaps.mCanAddRestrictedProfile);
// when isEnableGuestModeUxChanges() is true, the icon is set via the layout xml
if (!isEnableGuestModeUxChanges()) {
Drawable icon = context.getDrawable(R.drawable.ic_account_circle_filled);
mAddUser.setIcon(centerAndTint(icon));
}
}
private void updateAddSupervisedUser(Context context) {
if (!TextUtils.isEmpty(mConfigSupervisedUserCreationPackage)) {
updateAddUserCommon(context, mAddSupervisedUser, false);
// when isEnableGuestModeUxChanges() is true, the icon is set via the layout xml
if (!isEnableGuestModeUxChanges()) {
Drawable icon = context.getDrawable(R.drawable.ic_add_supervised_user);
mAddSupervisedUser.setIcon(centerAndTint(icon));
}
} else {
mAddSupervisedUser.setVisible(false);
}
@@ -1603,28 +1568,17 @@ public class UserSettings extends SettingsPreferenceFragment
@Override
public boolean onPreferenceClick(Preference pref) {
if (isCurrentUserGuest()) {
if (isEnableGuestModeUxChanges()) {
if (mGuestResetPreference != null && pref == mGuestResetPreference) {
showDialog(DIALOG_CONFIRM_RESET_AND_RESTART_GUEST);
return true;
}
if (mGuestExitPreference != null && pref == mGuestExitPreference) {
if (mUserCaps.mIsEphemeral) {
showDialog(DIALOG_CONFIRM_EXIT_GUEST_EPHEMERAL);
} else {
showDialog(DIALOG_CONFIRM_EXIT_GUEST_NON_EPHEMERAL);
}
return true;
}
} else {
if (mGuestExitPreference != null && pref == mGuestExitPreference) {
if (mGuestUserAutoCreated) {
showDialog(DIALOG_CONFIRM_REMOVE_GUEST_WITH_AUTO_CREATE);
} else {
showDialog(DIALOG_CONFIRM_REMOVE_GUEST);
}
return true;
if (mGuestResetPreference != null && pref == mGuestResetPreference) {
showDialog(DIALOG_CONFIRM_RESET_AND_RESTART_GUEST);
return true;
}
if (mGuestExitPreference != null && pref == mGuestExitPreference) {
if (mUserCaps.mIsEphemeral) {
showDialog(DIALOG_CONFIRM_EXIT_GUEST_EPHEMERAL);
} else {
showDialog(DIALOG_CONFIRM_EXIT_GUEST_NON_EPHEMERAL);
}
return true;
}
}
if (pref == mMePreference) {

View File

@@ -18,6 +18,8 @@ package com.android.settings.fuelgauge.batterytip.detectors;
import static com.google.common.truth.Truth.assertThat;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
@@ -42,7 +44,7 @@ public class BatteryDefenderDetectorTest {
mBatteryInfo.discharging = false;
mBatteryDefenderDetector = new BatteryDefenderDetector(
mBatteryInfo, /* extraDefend= */ false);
mBatteryInfo, ApplicationProvider.getApplicationContext());
}
@Test

View File

@@ -125,7 +125,7 @@ public class BatteryDefenderTipTest {
@Test
public void updatePreference_shouldSetSecondaryButtonText() {
String expected = mContext.getString(R.string.see_more);
String expected = mContext.getString(R.string.learn_more);
mBatteryDefenderTip.updatePreference(mCardPreference);

View File

@@ -426,7 +426,7 @@ public class NotificationPreferenceControllerTest {
private final class TestPreferenceController extends NotificationPreferenceController {
private TestPreferenceController(Context context, NotificationBackend backend) {
super(context, backend, "key");
super(context, backend);
}
@Override

View File

@@ -42,6 +42,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -74,6 +75,7 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.Arrays;
import java.util.concurrent.Executor;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowAlertDialogCompat.class)
@@ -81,6 +83,8 @@ public class SimSelectNotificationTest {
@Mock
private Context mContext;
@Mock
private Executor mExecutor;
@Mock
private NotificationManager mNotificationManager;
@Mock
private TelephonyManager mTelephonyManager;
@@ -94,6 +98,8 @@ public class SimSelectNotificationTest {
private SubscriptionInfo mSubInfo;
@Mock
private DisplayMetrics mDisplayMetrics;
@Mock
private SimDialogActivity mActivity;
private final String mFakeDisplayName = "fake_display_name";
private final CharSequence mFakeNotificationChannelTitle = "fake_notification_channel_title";
@@ -236,27 +242,18 @@ public class SimSelectNotificationTest {
@Test
public void onReceivePrimarySubListChange_WithDismissExtra_shouldDismiss() {
doReturn(mExecutor).when(mActivity).getMainExecutor();
SimDialogProhibitService.supportDismiss(mActivity);
Intent intent = new Intent(TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED);
intent.putExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE,
EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA);
EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS);
mSimSelectNotification.onReceive(mContext, intent);
clearInvocations(mContext);
// Dismiss.
intent.putExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE,
EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS);
mSimSelectNotification.onReceive(mContext, intent);
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mContext).startActivity(intentCaptor.capture());
Intent capturedIntent = intentCaptor.getValue();
assertThat(capturedIntent).isNotNull();
assertThat(capturedIntent.getComponent().getClassName()).isEqualTo(
SimDialogActivity.class.getName());
assertThat(capturedIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK)
.isNotEqualTo(0);
assertThat(capturedIntent.getIntExtra(SimDialogActivity.DIALOG_TYPE_KEY, INVALID_PICK))
.isEqualTo(PICK_DISMISS);
verify(mExecutor).execute(any());
}
@Test
public void onReceivePrimarySubListChange_DualCdmaWarning_notificationShouldSend() {

View File

@@ -0,0 +1,78 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.datausage;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.os.INetworkManagementService;
import android.os.RemoteException;
import android.os.UserManager;
import android.telephony.TelephonyManager;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@RunWith(AndroidJUnit4.class)
public class BillingCyclePreferenceTest {
private Context mContext;
private BillingCyclePreference mPreference;
private TemplatePreference.NetworkServices mServices;
@Mock
private INetworkManagementService mNetManageSerice;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private UserManager mUserManager;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
mServices = new TemplatePreference.NetworkServices();
mServices.mNetworkService = mNetManageSerice;
mServices.mTelephonyManager = mTelephonyManager;
mServices.mUserManager = mUserManager;
doReturn(mTelephonyManager).when(mTelephonyManager)
.createForSubscriptionId(anyInt());
mPreference = spy(new BillingCyclePreference(mContext, null /* attrs */));
mPreference.setTemplate(null, 0, mServices);
}
@Test
public void testPreferenceUpdate_onMobileDataEnabledChange_accessDataEnabledApi() {
try {
doReturn(true).when(mNetManageSerice).isBandwidthControlEnabled();
} catch (RemoteException exception) {}
doReturn(true).when(mUserManager).isAdminUser();
mPreference.onMobileDataEnabledChange();
verify(mTelephonyManager)
.isDataEnabledForReason(TelephonyManager.DATA_ENABLED_REASON_USER);
}
}