From e443e94cfaa64703e0ae6d1af72e4ecaf81240b7 Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Tue, 24 May 2022 18:00:34 +0800 Subject: [PATCH 01/20] Fix crash for DefaultSubscriptionController setSummaryProvider() is used instead of setSummary() in Ia24d88817c99db7ed3fc264dbc9c10e0a09d8a39, but there is still a place using the setSummary(), mixing these two will lead to crash. Change it to setSummaryProvider() to prevent crash. Fix: 233295254 Fix: 233712251 Test: manual Change-Id: I4627545711b848009c3bd7179f0368ff82e62697 (cherry picked from commit 2e34038233a99cefbf432d2b68851048246dfecb) Merged-In: I4627545711b848009c3bd7179f0368ff82e62697 --- .../network/telephony/DefaultSubscriptionController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java index 5511829a61a..a3a281c4198 100644 --- a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java +++ b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java @@ -168,8 +168,8 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere if (subs.size() == 1) { mPreference.setEnabled(false); - mPreference.setSummary(SubscriptionUtil.getUniqueSubscriptionDisplayName( - subs.get(0), mContext)); + mPreference.setSummaryProvider(pref -> + SubscriptionUtil.getUniqueSubscriptionDisplayName(subs.get(0), mContext)); return; } From 4b47339cef965b3576ff2bfb93f26934a8fcbe5f Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Tue, 24 May 2022 18:00:34 +0800 Subject: [PATCH 02/20] Fix crash for DefaultSubscriptionController setSummaryProvider() is used instead of setSummary() in Ia24d88817c99db7ed3fc264dbc9c10e0a09d8a39, but there is still a place using the setSummary(), mixing these two will lead to crash. Change it to setSummaryProvider() to prevent crash. Fix: 233295254 Fix: 233712251 Test: manual Change-Id: I4627545711b848009c3bd7179f0368ff82e62697 (cherry picked from commit 2e34038233a99cefbf432d2b68851048246dfecb) Merged-In: I4627545711b848009c3bd7179f0368ff82e62697 --- .../network/telephony/DefaultSubscriptionController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java index 5511829a61a..a3a281c4198 100644 --- a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java +++ b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java @@ -168,8 +168,8 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere if (subs.size() == 1) { mPreference.setEnabled(false); - mPreference.setSummary(SubscriptionUtil.getUniqueSubscriptionDisplayName( - subs.get(0), mContext)); + mPreference.setSummaryProvider(pref -> + SubscriptionUtil.getUniqueSubscriptionDisplayName(subs.get(0), mContext)); return; } From dbfea29ab047349f04d7d041753212670fd6e1b9 Mon Sep 17 00:00:00 2001 From: Neha Jain Date: Mon, 25 Jul 2022 22:16:16 +0000 Subject: [PATCH 03/20] Revert "Improve App notification loading" Revert "Fix binder error when an app has many channels" Revert submission 19290255-jr-bind-flicker Reason for revert: b/240100577 Reverted Changes: I9a1c96f75:Improve App notification loading I391ce0b10:Fix binder error when an app has many channels Change-Id: Iaae40de74d135a79c18201ec17e00f3d9d5f0f3b (cherry picked from commit c5f1cb11e0c895e1b62f8f3a0074cf30cfc7c4a8) Merged-In: Iaae40de74d135a79c18201ec17e00f3d9d5f0f3b --- .../AppBubbleListPreferenceController.java | 14 +-- .../AddToHomeScreenPreferenceController.java | 10 +- .../app/AllowSoundPreferenceController.java | 13 +-- ...nnelsBypassingDndPreferenceController.java | 6 +- ...pConversationListPreferenceController.java | 22 ++--- .../app/AppLinkPreferenceController.java | 10 +- .../app/BadgePreferenceController.java | 22 ++--- .../app/BlockPreferenceController.java | 10 +- .../BubbleCategoryPreferenceController.java | 10 +- .../app/BubbleLinkPreferenceController.java | 10 +- .../app/BubblePreferenceController.java | 19 ++-- .../BubbleSummaryPreferenceController.java | 21 ++--- .../app/ChannelListPreferenceController.java | 47 +++++----- ...onversationDemotePreferenceController.java | 15 ++- ...onversationHeaderPreferenceController.java | 6 +- ...versationPriorityPreferenceController.java | 12 +-- ...nversationPromotePreferenceController.java | 15 ++- .../DeletedChannelsPreferenceController.java | 15 ++- .../app/DescriptionPreferenceController.java | 16 ++-- .../app/DndPreferenceController.java | 10 +- .../app/HeaderPreferenceController.java | 6 +- .../HighImportancePreferenceController.java | 16 ++-- .../app/ImportancePreferenceController.java | 12 +-- ...dConversationInfoPreferenceController.java | 14 ++- ...validConversationPreferenceController.java | 14 ++- .../app/LightsPreferenceController.java | 18 ++-- .../MinImportancePreferenceController.java | 14 +-- .../app/NotificationPreferenceController.java | 33 +++---- .../app/NotificationSettings.java | 94 ++++++++++--------- .../NotificationsOffPreferenceController.java | 14 +-- .../app/SoundPreferenceController.java | 15 ++- .../app/VibrationPreferenceController.java | 19 ++-- .../app/VisibilityPreferenceController.java | 16 ++-- .../NotificationPreferenceControllerTest.java | 2 +- 34 files changed, 272 insertions(+), 318 deletions(-) diff --git a/src/com/android/settings/notification/AppBubbleListPreferenceController.java b/src/com/android/settings/notification/AppBubbleListPreferenceController.java index 6ebb376b5c1..bf7fcc03756 100644 --- a/src/com/android/settings/notification/AppBubbleListPreferenceController.java +++ b/src/com/android/settings/notification/AppBubbleListPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java b/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java index 12b807534f9..e5afd9d3db0 100644 --- a/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java +++ b/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/AllowSoundPreferenceController.java b/src/com/android/settings/notification/app/AllowSoundPreferenceController.java index 99d08734c96..0664c544bec 100644 --- a/src/com/android/settings/notification/app/AllowSoundPreferenceController.java +++ b/src/com/android/settings/notification/app/AllowSoundPreferenceController.java @@ -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()); } diff --git a/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java b/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java index 6c2c0c3cf77..92cd911843a 100644 --- a/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java +++ b/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/AppConversationListPreferenceController.java b/src/com/android/settings/notification/app/AppConversationListPreferenceController.java index e7b23788968..dd44a13f7c8 100644 --- a/src/com/android/settings/notification/app/AppConversationListPreferenceController.java +++ b/src/com/android/settings/notification/app/AppConversationListPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/AppLinkPreferenceController.java b/src/com/android/settings/notification/app/AppLinkPreferenceController.java index ecf9670cba9..043ae698f54 100644 --- a/src/com/android/settings/notification/app/AppLinkPreferenceController.java +++ b/src/com/android/settings/notification/app/AppLinkPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/BadgePreferenceController.java b/src/com/android/settings/notification/app/BadgePreferenceController.java index f94dfb513ae..108fa1d7a07 100644 --- a/src/com/android/settings/notification/app/BadgePreferenceController.java +++ b/src/com/android/settings/notification/app/BadgePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/BlockPreferenceController.java b/src/com/android/settings/notification/app/BlockPreferenceController.java index ea3eaeb3353..f4e213298a7 100644 --- a/src/com/android/settings/notification/app/BlockPreferenceController.java +++ b/src/com/android/settings/notification/app/BlockPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java b/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java index da67afeeb33..ad3a10cf381 100644 --- a/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java +++ b/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java b/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java index ed1c9b53079..0b9529b10b5 100644 --- a/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java +++ b/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/BubblePreferenceController.java b/src/com/android/settings/notification/app/BubblePreferenceController.java index 516a45e482d..351b4635bb6 100644 --- a/src/com/android/settings/notification/app/BubblePreferenceController.java +++ b/src/com/android/settings/notification/app/BubblePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java b/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java index abbe89e6fa8..51370b16bef 100644 --- a/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java +++ b/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/ChannelListPreferenceController.java b/src/com/android/settings/notification/app/ChannelListPreferenceController.java index 8d079114a9e..8db3b21f4be 100644 --- a/src/com/android/settings/notification/app/ChannelListPreferenceController.java +++ b/src/com/android/settings/notification/app/ChannelListPreferenceController.java @@ -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() { + @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. diff --git a/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java b/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java index ba7ca358b8b..02f639c3157 100644 --- a/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java +++ b/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java b/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java index 56de88b324a..f99a56aabda 100644 --- a/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java +++ b/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java b/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java index 46bc3c0c840..ae169282484 100644 --- a/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java +++ b/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java b/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java index a5ef569d620..24c3d2ff6a1 100644 --- a/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java +++ b/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java b/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java index cd160df1fd4..77a692f1488 100644 --- a/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java +++ b/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/DescriptionPreferenceController.java b/src/com/android/settings/notification/app/DescriptionPreferenceController.java index 413a876cec9..0a5bb2f9260 100644 --- a/src/com/android/settings/notification/app/DescriptionPreferenceController.java +++ b/src/com/android/settings/notification/app/DescriptionPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/DndPreferenceController.java b/src/com/android/settings/notification/app/DndPreferenceController.java index 811eeb4ec79..b65928aa915 100644 --- a/src/com/android/settings/notification/app/DndPreferenceController.java +++ b/src/com/android/settings/notification/app/DndPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/HeaderPreferenceController.java b/src/com/android/settings/notification/app/HeaderPreferenceController.java index c4b0e598dff..7379d55395b 100644 --- a/src/com/android/settings/notification/app/HeaderPreferenceController.java +++ b/src/com/android/settings/notification/app/HeaderPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/HighImportancePreferenceController.java b/src/com/android/settings/notification/app/HighImportancePreferenceController.java index 98dc8a760e2..d60668b9abe 100644 --- a/src/com/android/settings/notification/app/HighImportancePreferenceController.java +++ b/src/com/android/settings/notification/app/HighImportancePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/ImportancePreferenceController.java b/src/com/android/settings/notification/app/ImportancePreferenceController.java index 31ddac39373..3c32ca4b0bc 100644 --- a/src/com/android/settings/notification/app/ImportancePreferenceController.java +++ b/src/com/android/settings/notification/app/ImportancePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java b/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java index bb2c58b728b..b937e80e0d6 100644 --- a/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java +++ b/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java b/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java index 219ccbcea85..5c502dccbe0 100644 --- a/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java +++ b/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/LightsPreferenceController.java b/src/com/android/settings/notification/app/LightsPreferenceController.java index f7f92442c9b..d096922e348 100644 --- a/src/com/android/settings/notification/app/LightsPreferenceController.java +++ b/src/com/android/settings/notification/app/LightsPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/MinImportancePreferenceController.java b/src/com/android/settings/notification/app/MinImportancePreferenceController.java index b2c0862b8f8..f8257636615 100644 --- a/src/com/android/settings/notification/app/MinImportancePreferenceController.java +++ b/src/com/android/settings/notification/app/MinImportancePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/NotificationPreferenceController.java b/src/com/android/settings/notification/app/NotificationPreferenceController.java index 271a83d76f8..fb19d9d6b4c 100644 --- a/src/com/android/settings/notification/app/NotificationPreferenceController.java +++ b/src/com/android/settings/notification/app/NotificationPreferenceController.java @@ -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, diff --git a/src/com/android/settings/notification/app/NotificationSettings.java b/src/com/android/settings/notification/app/NotificationSettings.java index 5750167c271..192a0ee9fc7 100644 --- a/src/com/android/settings/notification/app/NotificationSettings.java +++ b/src/com/android/settings/notification/app/NotificationSettings.java @@ -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(); } diff --git a/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java b/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java index 46625c3101a..0c7cd2361e2 100644 --- a/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java +++ b/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/SoundPreferenceController.java b/src/com/android/settings/notification/app/SoundPreferenceController.java index 335b44226ce..b23b4fc86cb 100644 --- a/src/com/android/settings/notification/app/SoundPreferenceController.java +++ b/src/com/android/settings/notification/app/SoundPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/VibrationPreferenceController.java b/src/com/android/settings/notification/app/VibrationPreferenceController.java index f91999f074d..34d1a543b56 100644 --- a/src/com/android/settings/notification/app/VibrationPreferenceController.java +++ b/src/com/android/settings/notification/app/VibrationPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/VisibilityPreferenceController.java b/src/com/android/settings/notification/app/VisibilityPreferenceController.java index 3f33267a749..a2a1d76b71c 100644 --- a/src/com/android/settings/notification/app/VisibilityPreferenceController.java +++ b/src/com/android/settings/notification/app/VisibilityPreferenceController.java @@ -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 diff --git a/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java index bf529e67568..b2f1673f317 100644 --- a/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java @@ -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 From 2a2ab37e5d840d43358f4edb3b694f94684d3815 Mon Sep 17 00:00:00 2001 From: Neha Jain Date: Mon, 25 Jul 2022 22:16:16 +0000 Subject: [PATCH 04/20] Revert "Improve App notification loading" Revert "Fix binder error when an app has many channels" Revert submission 19290255-jr-bind-flicker Reason for revert: b/240100577 Reverted Changes: I9a1c96f75:Improve App notification loading I391ce0b10:Fix binder error when an app has many channels Change-Id: Iaae40de74d135a79c18201ec17e00f3d9d5f0f3b (cherry picked from commit c5f1cb11e0c895e1b62f8f3a0074cf30cfc7c4a8) Merged-In: Iaae40de74d135a79c18201ec17e00f3d9d5f0f3b --- .../AppBubbleListPreferenceController.java | 14 +-- .../AddToHomeScreenPreferenceController.java | 10 +- .../app/AllowSoundPreferenceController.java | 13 +-- ...nnelsBypassingDndPreferenceController.java | 6 +- ...pConversationListPreferenceController.java | 22 ++--- .../app/AppLinkPreferenceController.java | 10 +- .../app/BadgePreferenceController.java | 22 ++--- .../app/BlockPreferenceController.java | 10 +- .../BubbleCategoryPreferenceController.java | 10 +- .../app/BubbleLinkPreferenceController.java | 10 +- .../app/BubblePreferenceController.java | 19 ++-- .../BubbleSummaryPreferenceController.java | 21 ++--- .../app/ChannelListPreferenceController.java | 47 +++++----- ...onversationDemotePreferenceController.java | 15 ++- ...onversationHeaderPreferenceController.java | 6 +- ...versationPriorityPreferenceController.java | 12 +-- ...nversationPromotePreferenceController.java | 15 ++- .../DeletedChannelsPreferenceController.java | 15 ++- .../app/DescriptionPreferenceController.java | 16 ++-- .../app/DndPreferenceController.java | 10 +- .../app/HeaderPreferenceController.java | 6 +- .../HighImportancePreferenceController.java | 16 ++-- .../app/ImportancePreferenceController.java | 12 +-- ...dConversationInfoPreferenceController.java | 14 ++- ...validConversationPreferenceController.java | 14 ++- .../app/LightsPreferenceController.java | 18 ++-- .../MinImportancePreferenceController.java | 14 +-- .../app/NotificationPreferenceController.java | 33 +++---- .../app/NotificationSettings.java | 94 ++++++++++--------- .../NotificationsOffPreferenceController.java | 14 +-- .../app/SoundPreferenceController.java | 15 ++- .../app/VibrationPreferenceController.java | 19 ++-- .../app/VisibilityPreferenceController.java | 16 ++-- .../NotificationPreferenceControllerTest.java | 2 +- 34 files changed, 272 insertions(+), 318 deletions(-) diff --git a/src/com/android/settings/notification/AppBubbleListPreferenceController.java b/src/com/android/settings/notification/AppBubbleListPreferenceController.java index 6ebb376b5c1..bf7fcc03756 100644 --- a/src/com/android/settings/notification/AppBubbleListPreferenceController.java +++ b/src/com/android/settings/notification/AppBubbleListPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java b/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java index 12b807534f9..e5afd9d3db0 100644 --- a/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java +++ b/src/com/android/settings/notification/app/AddToHomeScreenPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/AllowSoundPreferenceController.java b/src/com/android/settings/notification/app/AllowSoundPreferenceController.java index 99d08734c96..0664c544bec 100644 --- a/src/com/android/settings/notification/app/AllowSoundPreferenceController.java +++ b/src/com/android/settings/notification/app/AllowSoundPreferenceController.java @@ -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()); } diff --git a/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java b/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java index 6c2c0c3cf77..92cd911843a 100644 --- a/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java +++ b/src/com/android/settings/notification/app/AppChannelsBypassingDndPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/AppConversationListPreferenceController.java b/src/com/android/settings/notification/app/AppConversationListPreferenceController.java index e7b23788968..dd44a13f7c8 100644 --- a/src/com/android/settings/notification/app/AppConversationListPreferenceController.java +++ b/src/com/android/settings/notification/app/AppConversationListPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/AppLinkPreferenceController.java b/src/com/android/settings/notification/app/AppLinkPreferenceController.java index ecf9670cba9..043ae698f54 100644 --- a/src/com/android/settings/notification/app/AppLinkPreferenceController.java +++ b/src/com/android/settings/notification/app/AppLinkPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/BadgePreferenceController.java b/src/com/android/settings/notification/app/BadgePreferenceController.java index f94dfb513ae..108fa1d7a07 100644 --- a/src/com/android/settings/notification/app/BadgePreferenceController.java +++ b/src/com/android/settings/notification/app/BadgePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/BlockPreferenceController.java b/src/com/android/settings/notification/app/BlockPreferenceController.java index ea3eaeb3353..f4e213298a7 100644 --- a/src/com/android/settings/notification/app/BlockPreferenceController.java +++ b/src/com/android/settings/notification/app/BlockPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java b/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java index da67afeeb33..ad3a10cf381 100644 --- a/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java +++ b/src/com/android/settings/notification/app/BubbleCategoryPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java b/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java index ed1c9b53079..0b9529b10b5 100644 --- a/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java +++ b/src/com/android/settings/notification/app/BubbleLinkPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/BubblePreferenceController.java b/src/com/android/settings/notification/app/BubblePreferenceController.java index 516a45e482d..351b4635bb6 100644 --- a/src/com/android/settings/notification/app/BubblePreferenceController.java +++ b/src/com/android/settings/notification/app/BubblePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java b/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java index abbe89e6fa8..51370b16bef 100644 --- a/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java +++ b/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/ChannelListPreferenceController.java b/src/com/android/settings/notification/app/ChannelListPreferenceController.java index 8d079114a9e..8db3b21f4be 100644 --- a/src/com/android/settings/notification/app/ChannelListPreferenceController.java +++ b/src/com/android/settings/notification/app/ChannelListPreferenceController.java @@ -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() { + @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. diff --git a/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java b/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java index ba7ca358b8b..02f639c3157 100644 --- a/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java +++ b/src/com/android/settings/notification/app/ConversationDemotePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java b/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java index 56de88b324a..f99a56aabda 100644 --- a/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java +++ b/src/com/android/settings/notification/app/ConversationHeaderPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java b/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java index 46bc3c0c840..ae169282484 100644 --- a/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java +++ b/src/com/android/settings/notification/app/ConversationPriorityPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java b/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java index a5ef569d620..24c3d2ff6a1 100644 --- a/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java +++ b/src/com/android/settings/notification/app/ConversationPromotePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java b/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java index cd160df1fd4..77a692f1488 100644 --- a/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java +++ b/src/com/android/settings/notification/app/DeletedChannelsPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/DescriptionPreferenceController.java b/src/com/android/settings/notification/app/DescriptionPreferenceController.java index 413a876cec9..0a5bb2f9260 100644 --- a/src/com/android/settings/notification/app/DescriptionPreferenceController.java +++ b/src/com/android/settings/notification/app/DescriptionPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/DndPreferenceController.java b/src/com/android/settings/notification/app/DndPreferenceController.java index 811eeb4ec79..b65928aa915 100644 --- a/src/com/android/settings/notification/app/DndPreferenceController.java +++ b/src/com/android/settings/notification/app/DndPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/HeaderPreferenceController.java b/src/com/android/settings/notification/app/HeaderPreferenceController.java index c4b0e598dff..7379d55395b 100644 --- a/src/com/android/settings/notification/app/HeaderPreferenceController.java +++ b/src/com/android/settings/notification/app/HeaderPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/HighImportancePreferenceController.java b/src/com/android/settings/notification/app/HighImportancePreferenceController.java index 98dc8a760e2..d60668b9abe 100644 --- a/src/com/android/settings/notification/app/HighImportancePreferenceController.java +++ b/src/com/android/settings/notification/app/HighImportancePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/ImportancePreferenceController.java b/src/com/android/settings/notification/app/ImportancePreferenceController.java index 31ddac39373..3c32ca4b0bc 100644 --- a/src/com/android/settings/notification/app/ImportancePreferenceController.java +++ b/src/com/android/settings/notification/app/ImportancePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java b/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java index bb2c58b728b..b937e80e0d6 100644 --- a/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java +++ b/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java b/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java index 219ccbcea85..5c502dccbe0 100644 --- a/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java +++ b/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/LightsPreferenceController.java b/src/com/android/settings/notification/app/LightsPreferenceController.java index f7f92442c9b..d096922e348 100644 --- a/src/com/android/settings/notification/app/LightsPreferenceController.java +++ b/src/com/android/settings/notification/app/LightsPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/MinImportancePreferenceController.java b/src/com/android/settings/notification/app/MinImportancePreferenceController.java index b2c0862b8f8..f8257636615 100644 --- a/src/com/android/settings/notification/app/MinImportancePreferenceController.java +++ b/src/com/android/settings/notification/app/MinImportancePreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/NotificationPreferenceController.java b/src/com/android/settings/notification/app/NotificationPreferenceController.java index 271a83d76f8..fb19d9d6b4c 100644 --- a/src/com/android/settings/notification/app/NotificationPreferenceController.java +++ b/src/com/android/settings/notification/app/NotificationPreferenceController.java @@ -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, diff --git a/src/com/android/settings/notification/app/NotificationSettings.java b/src/com/android/settings/notification/app/NotificationSettings.java index 5750167c271..192a0ee9fc7 100644 --- a/src/com/android/settings/notification/app/NotificationSettings.java +++ b/src/com/android/settings/notification/app/NotificationSettings.java @@ -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(); } diff --git a/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java b/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java index 46625c3101a..0c7cd2361e2 100644 --- a/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java +++ b/src/com/android/settings/notification/app/NotificationsOffPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/SoundPreferenceController.java b/src/com/android/settings/notification/app/SoundPreferenceController.java index 335b44226ce..b23b4fc86cb 100644 --- a/src/com/android/settings/notification/app/SoundPreferenceController.java +++ b/src/com/android/settings/notification/app/SoundPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/VibrationPreferenceController.java b/src/com/android/settings/notification/app/VibrationPreferenceController.java index f91999f074d..34d1a543b56 100644 --- a/src/com/android/settings/notification/app/VibrationPreferenceController.java +++ b/src/com/android/settings/notification/app/VibrationPreferenceController.java @@ -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 diff --git a/src/com/android/settings/notification/app/VisibilityPreferenceController.java b/src/com/android/settings/notification/app/VisibilityPreferenceController.java index 3f33267a749..a2a1d76b71c 100644 --- a/src/com/android/settings/notification/app/VisibilityPreferenceController.java +++ b/src/com/android/settings/notification/app/VisibilityPreferenceController.java @@ -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 diff --git a/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java index bf529e67568..b2f1673f317 100644 --- a/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/NotificationPreferenceControllerTest.java @@ -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 From 07ba5fa61d00a6565765e826e904ede07fcc9fca Mon Sep 17 00:00:00 2001 From: William Escande Date: Thu, 3 Nov 2022 12:09:55 -0700 Subject: [PATCH 05/20] Fetch currently loaded bluetooth name Test: m ROBOTEST_FILTER="BluetoothMaxConnectedAudioDevicesPreferenceControllerTest" RunSettingsRoboTests -j40 Test: Open developper settings Bug: 257158801 Change-Id: Ib40a6264d8d6908103d76b6401ddcfd3ffa7dd88 (cherry picked from commit e2c6d1f60dde927daeb84226a1b025a582b2a9be) Merged-In: Ib40a6264d8d6908103d76b6401ddcfd3ffa7dd88 --- .../bluetooth/BluetoothPermissionRequest.java | 10 +++- src/com/android/settings/bluetooth/Utils.java | 51 +++++++++++++++++++ ...ectedAudioDevicesPreferenceController.java | 18 +++---- ...dAudioDevicesPreferenceControllerTest.java | 21 ++++---- 4 files changed, 78 insertions(+), 22 deletions(-) mode change 100755 => 100644 src/com/android/settings/bluetooth/Utils.java diff --git a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java index 8542fcd2461..a62bbe10e0c 100644 --- a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java +++ b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java @@ -24,6 +24,7 @@ import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager.NameNotFoundException; import android.os.PowerManager; import android.os.UserManager; import android.util.Log; @@ -125,8 +126,15 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver { // Create an intent triggered by clicking on the // "Clear All Notifications" button + String bluetoothName; + try { + bluetoothName = Utils.findBluetoothPackageName(context); + } catch (NameNotFoundException e) { + e.printStackTrace(); + return; + } Intent deleteIntent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY); - deleteIntent.setPackage("com.android.bluetooth"); + deleteIntent.setPackage(bluetoothName); deleteIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); deleteIntent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT, BluetoothDevice.CONNECTION_ACCESS_NO); diff --git a/src/com/android/settings/bluetooth/Utils.java b/src/com/android/settings/bluetooth/Utils.java old mode 100755 new mode 100644 index ca8f9d39a8c..24fe4e151ff --- a/src/com/android/settings/bluetooth/Utils.java +++ b/src/com/android/settings/bluetooth/Utils.java @@ -16,11 +16,18 @@ package com.android.settings.bluetooth; +import static android.os.Process.BLUETOOTH_UID; + import android.app.settings.SettingsEnums; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.content.DialogInterface; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.os.UserHandle; import android.provider.DeviceConfig; import android.provider.Settings; import android.text.TextUtils; @@ -189,4 +196,48 @@ public final class Utils { } return false; } + + /** + * Returns the Bluetooth Package name + */ + public static String findBluetoothPackageName(Context context) + throws NameNotFoundException { + // this activity will always be in the package where the rest of Bluetooth lives + String sentinelActivity = "com.android.bluetooth.opp.BluetoothOppLauncherActivity"; + PackageManager packageManager = context.createContextAsUser(UserHandle.SYSTEM, 0) + .getPackageManager(); + String[] allPackages = packageManager.getPackagesForUid(BLUETOOTH_UID); + String matchedPackage = null; + for (String candidatePackage : allPackages) { + PackageInfo packageInfo; + try { + packageInfo = + packageManager.getPackageInfo( + candidatePackage, + PackageManager.GET_ACTIVITIES + | PackageManager.MATCH_ANY_USER + | PackageManager.MATCH_UNINSTALLED_PACKAGES + | PackageManager.MATCH_DISABLED_COMPONENTS); + } catch (NameNotFoundException e) { + // rethrow + throw e; + } + if (packageInfo.activities == null) { + continue; + } + for (ActivityInfo activity : packageInfo.activities) { + if (sentinelActivity.equals(activity.name)) { + if (matchedPackage == null) { + matchedPackage = candidatePackage; + } else { + throw new NameNotFoundException("multiple main bluetooth packages found"); + } + } + } + } + if (matchedPackage != null) { + return matchedPackage; + } + throw new NameNotFoundException("Could not find main bluetooth package"); + } } diff --git a/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java b/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java index bd8169a80fe..f1677f29509 100644 --- a/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java +++ b/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java @@ -16,9 +16,8 @@ package com.android.settings.development; +import android.bluetooth.BluetoothManager; import android.content.Context; -import android.content.pm.PackageManager; -import android.content.res.Resources; import android.os.SystemProperties; import androidx.annotation.VisibleForTesting; @@ -42,18 +41,15 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceController extends private int mDefaultMaxConnectedAudioDevices = 0; + private final BluetoothManager mBluetoothManager; + public BluetoothMaxConnectedAudioDevicesPreferenceController(Context context) { super(context); - try { - Resources res = context.getPackageManager().getResourcesForApplication( - "com.android.bluetooth"); - mDefaultMaxConnectedAudioDevices = res.getInteger(res.getIdentifier( - "config_bluetooth_max_connected_audio_devices", - "integer", "com.android.bluetooth")); - } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); - } + mBluetoothManager = context.getSystemService(BluetoothManager.class); + + mDefaultMaxConnectedAudioDevices = + mBluetoothManager.getAdapter().getMaxConnectedAudioDevices(); } @Override diff --git a/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java index 72477b94585..7ab311fe2ab 100644 --- a/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java @@ -24,9 +24,9 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothManager; import android.content.Context; -import android.content.pm.PackageManager; -import android.content.res.Resources; import android.os.SystemProperties; @@ -54,6 +54,11 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest { @Spy private Context mSpyContext = RuntimeEnvironment.application; + @Mock + private BluetoothManager mBluetoothManager; + @Mock + private BluetoothAdapter mBluetoothAdapter; + private ListPreference mPreference; private BluetoothMaxConnectedAudioDevicesPreferenceController mController; @@ -63,19 +68,15 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest { @Before public void setup() { MockitoAnnotations.initMocks(this); + doReturn(mBluetoothManager).when(mSpyContext).getSystemService(BluetoothManager.class); + doReturn(mBluetoothAdapter).when(mBluetoothManager).getAdapter(); // Get XML values without mock // Setup test list preference using XML values mPreference = new ListPreference(mSpyContext); mPreference.setEntries(R.array.bluetooth_max_connected_audio_devices); mPreference.setEntryValues(R.array.bluetooth_max_connected_audio_devices_values); - // Retrieve default max connected audio devices to a test controlled value - try { - Resources res = mSpyContext.getPackageManager().getResourcesForApplication("com.android.bluetooth"); - TEST_MAX_CONNECTED_AUDIO_DEVICES = res.getInteger(res.getIdentifier("config_bluetooth_max_connected_audio_devices", "integer", "com.android.bluetooth")); - } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); - } - + doReturn(TEST_MAX_CONNECTED_AUDIO_DEVICES).when(mBluetoothAdapter) + .getMaxConnectedAudioDevices(); // Init the actual controller mController = new BluetoothMaxConnectedAudioDevicesPreferenceController(mSpyContext); // Construct preference in the controller via a mocked preference screen object From 8f8801ac4aa70670c4f107a75a8ef4f427b597fa Mon Sep 17 00:00:00 2001 From: William Escande Date: Thu, 3 Nov 2022 12:09:55 -0700 Subject: [PATCH 06/20] Fetch currently loaded bluetooth name Test: m ROBOTEST_FILTER="BluetoothMaxConnectedAudioDevicesPreferenceControllerTest" RunSettingsRoboTests -j40 Test: m ROBOTEST_FILTER="com.android.settings.bluetooth" RunSettingsRoboTests Test: Open developer settings Bug: 257158801 Change-Id: Ib40a6264d8d6908103d76b6401ddcfd3ffa7dd88 (cherry picked from commit 723df89aaa80f1b4b2afe7819d390691d385ecbd) Merged-In: Ib40a6264d8d6908103d76b6401ddcfd3ffa7dd88 --- .../bluetooth/BluetoothPermissionRequest.java | 10 +++- src/com/android/settings/bluetooth/Utils.java | 51 +++++++++++++++++++ ...ectedAudioDevicesPreferenceController.java | 18 +++---- ...dAudioDevicesPreferenceControllerTest.java | 21 ++++---- 4 files changed, 78 insertions(+), 22 deletions(-) mode change 100755 => 100644 src/com/android/settings/bluetooth/Utils.java diff --git a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java index 8542fcd2461..a62bbe10e0c 100644 --- a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java +++ b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java @@ -24,6 +24,7 @@ import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager.NameNotFoundException; import android.os.PowerManager; import android.os.UserManager; import android.util.Log; @@ -125,8 +126,15 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver { // Create an intent triggered by clicking on the // "Clear All Notifications" button + String bluetoothName; + try { + bluetoothName = Utils.findBluetoothPackageName(context); + } catch (NameNotFoundException e) { + e.printStackTrace(); + return; + } Intent deleteIntent = new Intent(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY); - deleteIntent.setPackage("com.android.bluetooth"); + deleteIntent.setPackage(bluetoothName); deleteIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); deleteIntent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT, BluetoothDevice.CONNECTION_ACCESS_NO); diff --git a/src/com/android/settings/bluetooth/Utils.java b/src/com/android/settings/bluetooth/Utils.java old mode 100755 new mode 100644 index ca8f9d39a8c..24fe4e151ff --- a/src/com/android/settings/bluetooth/Utils.java +++ b/src/com/android/settings/bluetooth/Utils.java @@ -16,11 +16,18 @@ package com.android.settings.bluetooth; +import static android.os.Process.BLUETOOTH_UID; + import android.app.settings.SettingsEnums; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.content.DialogInterface; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.os.UserHandle; import android.provider.DeviceConfig; import android.provider.Settings; import android.text.TextUtils; @@ -189,4 +196,48 @@ public final class Utils { } return false; } + + /** + * Returns the Bluetooth Package name + */ + public static String findBluetoothPackageName(Context context) + throws NameNotFoundException { + // this activity will always be in the package where the rest of Bluetooth lives + String sentinelActivity = "com.android.bluetooth.opp.BluetoothOppLauncherActivity"; + PackageManager packageManager = context.createContextAsUser(UserHandle.SYSTEM, 0) + .getPackageManager(); + String[] allPackages = packageManager.getPackagesForUid(BLUETOOTH_UID); + String matchedPackage = null; + for (String candidatePackage : allPackages) { + PackageInfo packageInfo; + try { + packageInfo = + packageManager.getPackageInfo( + candidatePackage, + PackageManager.GET_ACTIVITIES + | PackageManager.MATCH_ANY_USER + | PackageManager.MATCH_UNINSTALLED_PACKAGES + | PackageManager.MATCH_DISABLED_COMPONENTS); + } catch (NameNotFoundException e) { + // rethrow + throw e; + } + if (packageInfo.activities == null) { + continue; + } + for (ActivityInfo activity : packageInfo.activities) { + if (sentinelActivity.equals(activity.name)) { + if (matchedPackage == null) { + matchedPackage = candidatePackage; + } else { + throw new NameNotFoundException("multiple main bluetooth packages found"); + } + } + } + } + if (matchedPackage != null) { + return matchedPackage; + } + throw new NameNotFoundException("Could not find main bluetooth package"); + } } diff --git a/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java b/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java index bd8169a80fe..f1677f29509 100644 --- a/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java +++ b/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java @@ -16,9 +16,8 @@ package com.android.settings.development; +import android.bluetooth.BluetoothManager; import android.content.Context; -import android.content.pm.PackageManager; -import android.content.res.Resources; import android.os.SystemProperties; import androidx.annotation.VisibleForTesting; @@ -42,18 +41,15 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceController extends private int mDefaultMaxConnectedAudioDevices = 0; + private final BluetoothManager mBluetoothManager; + public BluetoothMaxConnectedAudioDevicesPreferenceController(Context context) { super(context); - try { - Resources res = context.getPackageManager().getResourcesForApplication( - "com.android.bluetooth"); - mDefaultMaxConnectedAudioDevices = res.getInteger(res.getIdentifier( - "config_bluetooth_max_connected_audio_devices", - "integer", "com.android.bluetooth")); - } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); - } + mBluetoothManager = context.getSystemService(BluetoothManager.class); + + mDefaultMaxConnectedAudioDevices = + mBluetoothManager.getAdapter().getMaxConnectedAudioDevices(); } @Override diff --git a/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java index 72477b94585..7ab311fe2ab 100644 --- a/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java @@ -24,9 +24,9 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothManager; import android.content.Context; -import android.content.pm.PackageManager; -import android.content.res.Resources; import android.os.SystemProperties; @@ -54,6 +54,11 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest { @Spy private Context mSpyContext = RuntimeEnvironment.application; + @Mock + private BluetoothManager mBluetoothManager; + @Mock + private BluetoothAdapter mBluetoothAdapter; + private ListPreference mPreference; private BluetoothMaxConnectedAudioDevicesPreferenceController mController; @@ -63,19 +68,15 @@ public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest { @Before public void setup() { MockitoAnnotations.initMocks(this); + doReturn(mBluetoothManager).when(mSpyContext).getSystemService(BluetoothManager.class); + doReturn(mBluetoothAdapter).when(mBluetoothManager).getAdapter(); // Get XML values without mock // Setup test list preference using XML values mPreference = new ListPreference(mSpyContext); mPreference.setEntries(R.array.bluetooth_max_connected_audio_devices); mPreference.setEntryValues(R.array.bluetooth_max_connected_audio_devices_values); - // Retrieve default max connected audio devices to a test controlled value - try { - Resources res = mSpyContext.getPackageManager().getResourcesForApplication("com.android.bluetooth"); - TEST_MAX_CONNECTED_AUDIO_DEVICES = res.getInteger(res.getIdentifier("config_bluetooth_max_connected_audio_devices", "integer", "com.android.bluetooth")); - } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); - } - + doReturn(TEST_MAX_CONNECTED_AUDIO_DEVICES).when(mBluetoothAdapter) + .getMaxConnectedAudioDevices(); // Init the actual controller mController = new BluetoothMaxConnectedAudioDevicesPreferenceController(mSpyContext); // Construct preference in the controller via a mocked preference screen object From 0f76fb222f2bbefcac4025be153abf057de8b31e Mon Sep 17 00:00:00 2001 From: Yi-Ling Chuang Date: Fri, 4 Nov 2022 10:03:25 +0800 Subject: [PATCH 07/20] Remove BatteryFixSlice as it's not used The BatteryFixSlice hasn't been used for a while, and it's introducing memory leaks due to a design change at the framework's end. Hence, remove it. Bug: 245385410 Test: robotests Change-Id: I517cab71a32613d5cb5fcd3beb991a24926a2902 (cherry picked from commit e3fcf1f08208d45821b95dc6fa64cd13f049fe84) Merged-In: I517cab71a32613d5cb5fcd3beb991a24926a2902 --- .../fuelgauge/BatteryBroadcastReceiver.java | 2 - .../SettingsContextualCardProvider.java | 7 - .../slices/BatteryFixSlice.java | 258 ------------------ .../settings/slices/CustomSliceRegistry.java | 13 - .../accounts/AvatarViewMixinTest.java | 2 - .../BatteryBroadcastReceiverTest.java | 20 -- .../SettingsHomepageActivityTest.java | 7 - .../ContextualCardManagerTest.java | 6 +- .../slices/BatteryFixSliceTest.java | 207 -------------- 9 files changed, 3 insertions(+), 519 deletions(-) delete mode 100644 src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java delete mode 100644 tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java diff --git a/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java index 436cde809a8..558e0bfb391 100644 --- a/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java +++ b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java @@ -28,7 +28,6 @@ import androidx.annotation.IntDef; import androidx.annotation.VisibleForTesting; import com.android.settings.Utils; -import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -135,6 +134,5 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver { mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_SAVER); } } - BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext); } } \ No newline at end of file diff --git a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java index 067fcf90e00..81142c20569 100644 --- a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java +++ b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java @@ -50,12 +50,6 @@ public class SettingsContextualCardProvider extends ContextualCardProvider { .setCardName(CustomSliceRegistry.LOW_STORAGE_SLICE_URI.toString()) .setCardCategory(ContextualCard.Category.IMPORTANT) .build(); - final ContextualCard batteryFixCard = - ContextualCard.newBuilder() - .setSliceUri(CustomSliceRegistry.BATTERY_FIX_SLICE_URI.toString()) - .setCardName(CustomSliceRegistry.BATTERY_FIX_SLICE_URI.toString()) - .setCardCategory(ContextualCard.Category.IMPORTANT) - .build(); final String contextualAdaptiveSleepSliceUri = CustomSliceRegistry.CONTEXTUAL_ADAPTIVE_SLEEP_URI.toString(); final ContextualCard contextualAdaptiveSleepCard = @@ -80,7 +74,6 @@ public class SettingsContextualCardProvider extends ContextualCardProvider { .addCard(wifiCard) .addCard(connectedDeviceCard) .addCard(lowStorageCard) - .addCard(batteryFixCard) .addCard(contextualAdaptiveSleepCard) .addCard(contextualFaceSettingsCard) .addCard(darkThemeCard) diff --git a/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java b/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java deleted file mode 100644 index 33dcd4e7972..00000000000 --- a/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright (C) 2018 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.homepage.contextualcards.slices; - -import static android.content.Context.MODE_PRIVATE; - -import static com.android.settings.slices.CustomSliceRegistry.BATTERY_FIX_SLICE_URI; - -import android.app.PendingIntent; -import android.app.settings.SettingsEnums; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffColorFilter; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.os.BatteryUsageStats; -import android.util.ArrayMap; -import android.view.View; - -import androidx.annotation.VisibleForTesting; -import androidx.annotation.WorkerThread; -import androidx.core.graphics.drawable.IconCompat; -import androidx.slice.Slice; -import androidx.slice.builders.ListBuilder; -import androidx.slice.builders.ListBuilder.RowBuilder; -import androidx.slice.builders.SliceAction; - -import com.android.settings.R; -import com.android.settings.SubSettings; -import com.android.settings.Utils; -import com.android.settings.fuelgauge.batterytip.BatteryTipLoader; -import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController; -import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; -import com.android.settings.fuelgauge.batteryusage.BatteryUsageStatsLoader; -import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary; -import com.android.settings.slices.CustomSliceable; -import com.android.settings.slices.SliceBackgroundWorker; -import com.android.settings.slices.SliceBuilderUtils; -import com.android.settingslib.utils.ThreadUtils; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -public class BatteryFixSlice implements CustomSliceable { - - @VisibleForTesting - static final String PREFS = "battery_fix_prefs"; - @VisibleForTesting - static final String KEY_CURRENT_TIPS_TYPE = "current_tip_type"; - static final String KEY_CURRENT_TIPS_STATE = "current_tip_state"; - - // A map tracking which BatteryTip and which state of that tip is not important. - private static final Map> UNIMPORTANT_BATTERY_TIPS; - - static { - UNIMPORTANT_BATTERY_TIPS = new ArrayMap<>(); - UNIMPORTANT_BATTERY_TIPS.put(BatteryTip.TipType.SUMMARY, - Arrays.asList(BatteryTip.StateType.NEW, BatteryTip.StateType.HANDLED)); - UNIMPORTANT_BATTERY_TIPS.put(BatteryTip.TipType.HIGH_DEVICE_USAGE, - Arrays.asList(BatteryTip.StateType.NEW, BatteryTip.StateType.HANDLED)); - UNIMPORTANT_BATTERY_TIPS.put(BatteryTip.TipType.BATTERY_SAVER, - Arrays.asList(BatteryTip.StateType.HANDLED)); - } - - private static final String TAG = "BatteryFixSlice"; - - private final Context mContext; - - public BatteryFixSlice(Context context) { - mContext = context; - } - - @Override - public Uri getUri() { - return BATTERY_FIX_SLICE_URI; - } - - @Override - public Slice getSlice() { - final ListBuilder sliceBuilder = - new ListBuilder(mContext, BATTERY_FIX_SLICE_URI, ListBuilder.INFINITY) - .setAccentColor(COLOR_NOT_TINTED); - - if (!isBatteryTipAvailableFromCache(mContext)) { - return buildBatteryGoodSlice(sliceBuilder, true /* isError */); - } - - final SliceBackgroundWorker worker = SliceBackgroundWorker.getInstance(getUri()); - final List batteryTips = worker != null ? worker.getResults() : null; - - if (batteryTips == null) { - // Because we need wait slice background worker return data - return buildBatteryGoodSlice(sliceBuilder, false /* isError */); - } - - for (BatteryTip batteryTip : batteryTips) { - if (batteryTip.getState() == BatteryTip.StateType.INVISIBLE) { - continue; - } - final Drawable drawable = mContext.getDrawable(batteryTip.getIconId()); - final int iconTintColorId = batteryTip.getIconTintColorId(); - if (iconTintColorId != View.NO_ID) { - drawable.setColorFilter(new PorterDuffColorFilter( - mContext.getResources().getColor(iconTintColorId), - PorterDuff.Mode.SRC_IN)); - } - - final IconCompat icon = Utils.createIconWithDrawable(drawable); - final SliceAction primaryAction = SliceAction.createDeeplink(getPrimaryAction(), - icon, - ListBuilder.ICON_IMAGE, - batteryTip.getTitle(mContext)); - sliceBuilder.addRow(new RowBuilder() - .setTitleItem(icon, ListBuilder.ICON_IMAGE) - .setTitle(batteryTip.getTitle(mContext)) - .setSubtitle(batteryTip.getSummary(mContext)) - .setPrimaryAction(primaryAction)); - break; - } - return sliceBuilder.build(); - } - - @Override - public Intent getIntent() { - final String screenTitle = mContext.getText(R.string.power_usage_summary_title) - .toString(); - final Uri contentUri = new Uri.Builder() - .appendPath(BatteryTipPreferenceController.PREF_NAME).build(); - - return SliceBuilderUtils.buildSearchResultPageIntent(mContext, - PowerUsageSummary.class.getName(), BatteryTipPreferenceController.PREF_NAME, - screenTitle, - SettingsEnums.SLICE, - this) - .setClassName(mContext.getPackageName(), SubSettings.class.getName()) - .setData(contentUri); - } - - @Override - public int getSliceHighlightMenuRes() { - return R.string.menu_key_battery; - } - - @Override - public void onNotifyChange(Intent intent) { - } - - @Override - public Class getBackgroundWorkerClass() { - return BatteryTipWorker.class; - } - - private PendingIntent getPrimaryAction() { - final Intent intent = getIntent(); - return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, - PendingIntent.FLAG_IMMUTABLE); - } - - private Slice buildBatteryGoodSlice(ListBuilder sliceBuilder, boolean isError) { - final IconCompat icon = IconCompat.createWithResource(mContext, - R.drawable.ic_battery_status_good_24dp); - final String title = mContext.getString(R.string.power_usage_summary_title); - final SliceAction primaryAction = SliceAction.createDeeplink(getPrimaryAction(), icon, - ListBuilder.ICON_IMAGE, title); - sliceBuilder.addRow(new RowBuilder() - .setTitleItem(icon, ListBuilder.ICON_IMAGE) - .setTitle(title) - .setPrimaryAction(primaryAction)) - .setIsError(isError); - return sliceBuilder.build(); - } - - // TODO(b/114807643): we should find a better way to get current battery tip type quickly - // Now we save battery tip type to shared preference when battery level changes - public static void updateBatteryTipAvailabilityCache(Context context) { - ThreadUtils.postOnBackgroundThread(() -> refreshBatteryTips(context)); - } - - - @VisibleForTesting - static boolean isBatteryTipAvailableFromCache(Context context) { - final SharedPreferences prefs = context.getSharedPreferences(PREFS, MODE_PRIVATE); - - final int type = prefs.getInt(KEY_CURRENT_TIPS_TYPE, BatteryTip.TipType.SUMMARY); - final int state = prefs.getInt(KEY_CURRENT_TIPS_STATE, BatteryTip.StateType.INVISIBLE); - if (state == BatteryTip.StateType.INVISIBLE) { - // State is INVISIBLE, We should not show anything. - return false; - } - final boolean unimportant = UNIMPORTANT_BATTERY_TIPS.containsKey(type) - && UNIMPORTANT_BATTERY_TIPS.get(type).contains(state); - return !unimportant; - } - - @WorkerThread - @VisibleForTesting - static List refreshBatteryTips(Context context) { - final BatteryUsageStatsLoader statsLoader = new BatteryUsageStatsLoader(context, - /* includeBatteryHistory */ false); - final BatteryUsageStats batteryUsageStats = statsLoader.loadInBackground(); - final BatteryTipLoader loader = new BatteryTipLoader(context, batteryUsageStats); - final List batteryTips = loader.loadInBackground(); - for (BatteryTip batteryTip : batteryTips) { - if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) { - context.getSharedPreferences(PREFS, MODE_PRIVATE) - .edit() - .putInt(KEY_CURRENT_TIPS_TYPE, batteryTip.getType()) - .putInt(KEY_CURRENT_TIPS_STATE, batteryTip.getState()) - .apply(); - break; - } - } - return batteryTips; - } - - public static class BatteryTipWorker extends SliceBackgroundWorker { - - private final Context mContext; - - public BatteryTipWorker(Context context, Uri uri) { - super(context, uri); - mContext = context; - } - - @Override - protected void onSlicePinned() { - ThreadUtils.postOnBackgroundThread(() -> { - final List batteryTips = refreshBatteryTips(mContext); - updateResults(batteryTips); - }); - } - - @Override - protected void onSliceUnpinned() { - } - - @Override - public void close() { - } - } -} diff --git a/src/com/android/settings/slices/CustomSliceRegistry.java b/src/com/android/settings/slices/CustomSliceRegistry.java index 1cc3276f1ce..217c1e963be 100644 --- a/src/com/android/settings/slices/CustomSliceRegistry.java +++ b/src/com/android/settings/slices/CustomSliceRegistry.java @@ -29,8 +29,6 @@ import androidx.annotation.VisibleForTesting; import com.android.settings.display.AlwaysOnDisplaySlice; import com.android.settings.display.ScreenTimeoutPreferenceController; import com.android.settings.flashlight.FlashlightSlice; -import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController; -import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice; import com.android.settings.homepage.contextualcards.slices.BluetoothDevicesSlice; import com.android.settings.homepage.contextualcards.slices.ContextualAdaptiveSleepSlice; import com.android.settings.homepage.contextualcards.slices.DarkThemeSlice; @@ -64,16 +62,6 @@ public class CustomSliceRegistry { .appendPath(ScreenTimeoutPreferenceController.PREF_NAME) .build(); - /** - * Uri for Battery Fix Slice. - */ - public static final Uri BATTERY_FIX_SLICE_URI = new Uri.Builder() - .scheme(ContentResolver.SCHEME_CONTENT) - .authority(SettingsSliceProvider.SLICE_AUTHORITY) - .appendEncodedPath(SettingsSlicesContract.PATH_SETTING_INTENT) - .appendPath(BatteryTipPreferenceController.PREF_NAME) - .build(); - /** * Backing Uri for the Bluetooth Slice. */ @@ -332,7 +320,6 @@ public class CustomSliceRegistry { // Slices for contextual card. sUriToSlice.put(FACE_ENROLL_SLICE_URI, FaceSetupSlice.class); - sUriToSlice.put(BATTERY_FIX_SLICE_URI, BatteryFixSlice.class); sUriToSlice.put(CONTEXTUAL_ADAPTIVE_SLEEP_URI, ContextualAdaptiveSleepSlice.class); sUriToSlice.put(CONTEXTUAL_WIFI_SLICE_URI, ContextualWifiSlice.class); sUriToSlice.put(LOW_STORAGE_SLICE_URI, LowStorageSlice.class); diff --git a/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java b/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java index 04db5270ec7..61017f71ee0 100644 --- a/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java +++ b/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java @@ -41,7 +41,6 @@ import android.os.Bundle; import android.widget.ImageView; import com.android.settings.homepage.SettingsHomepageActivity; -import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest; import com.android.settings.testutils.shadow.ShadowUserManager; import org.junit.Before; @@ -95,7 +94,6 @@ public class AvatarViewMixinTest { } @Test - @Config(shadows = BatteryFixSliceTest.ShadowBatteryTipLoader.class) public void onStart_useMockAvatarViewMixin_shouldBeExecuted() { final AvatarViewMixin mockAvatar = spy(new AvatarViewMixin(mActivity, mImageView)); diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java index d4469301894..867d8f44b7e 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java @@ -33,7 +33,6 @@ import android.os.BatteryManager; import android.os.PowerManager; import com.android.settings.Utils; -import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest; import org.junit.Before; import org.junit.Test; @@ -42,7 +41,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; -import org.robolectric.annotation.Config; @RunWith(RobolectricTestRunner.class) public class BatteryBroadcastReceiverTest { @@ -77,9 +75,6 @@ public class BatteryBroadcastReceiverTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void testOnReceive_batteryLevelChanged_dataUpdated() { mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent); @@ -91,9 +86,6 @@ public class BatteryBroadcastReceiverTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void testOnReceive_batteryHealthChanged_dataUpdated() { mChargingIntent .putExtra(BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_OVERHEAT); @@ -105,9 +97,6 @@ public class BatteryBroadcastReceiverTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void onReceive_batteryNotPresent_shouldShowHelpMessage() { mChargingIntent.putExtra(BatteryManager.EXTRA_PRESENT, false); @@ -117,9 +106,6 @@ public class BatteryBroadcastReceiverTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void testOnReceive_powerSaveModeChanged_listenerInvoked() { mBatteryBroadcastReceiver.onReceive(mContext, new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)); @@ -128,9 +114,6 @@ public class BatteryBroadcastReceiverTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void testOnReceive_batteryDataNotChanged_listenerNotInvoked() { final String batteryLevel = Utils.getBatteryPercentage(mChargingIntent); final String batteryStatus = @@ -148,9 +131,6 @@ public class BatteryBroadcastReceiverTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void testRegister_updateBatteryStatus() { doReturn(mChargingIntent).when(mContext).registerReceiver(any(), any()); diff --git a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java index b3feef413fe..719ce289971 100644 --- a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java +++ b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java @@ -38,7 +38,6 @@ import androidx.fragment.app.Fragment; import com.android.settings.R; import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl; -import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest; import com.android.settings.testutils.shadow.ShadowActivityEmbeddingUtils; import com.android.settings.testutils.shadow.ShadowUserManager; import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin; @@ -150,9 +149,6 @@ public class SettingsHomepageActivityTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void onStart_isNotDebuggable_shouldHideSystemOverlay() { ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false); @@ -169,9 +165,6 @@ public class SettingsHomepageActivityTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class, - }) public void onStop_isNotDebuggable_shouldRemoveHideSystemOverlay() { ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false); diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java index 69333d7ad9d..f18d94f828b 100644 --- a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java +++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java @@ -135,7 +135,7 @@ public class ContextualCardManagerTest { final List actualCards = mManager.mSavedCards.stream().collect(Collectors.toList()); final List expectedCards = Arrays.asList("test_low_storage", "test_flashlight", - "test_dark_theme", "test_gesture", "test_battery"); + "test_dark_theme", "test_gesture", "test_face_enroll"); assertThat(actualCards).containsExactlyElementsIn(expectedCards); } @@ -695,9 +695,9 @@ public class ContextualCardManagerTest { .setViewType(VIEW_TYPE_FULL_WIDTH) .build()); cards.add(new ContextualCard.Builder() - .setName("test_battery") + .setName("test_face_enroll") .setCardType(ContextualCard.CardType.SLICE) - .setSliceUri(CustomSliceRegistry.BATTERY_FIX_SLICE_URI) + .setSliceUri(CustomSliceRegistry.FACE_ENROLL_SLICE_URI) .setViewType(VIEW_TYPE_FULL_WIDTH) .build()); return cards; diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java deleted file mode 100644 index 78541db4947..00000000000 --- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) 2018 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.homepage.contextualcards.slices; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import android.content.Context; -import android.net.Uri; -import android.os.BatteryUsageStats; - -import androidx.slice.Slice; -import androidx.slice.SliceMetadata; -import androidx.slice.SliceProvider; -import androidx.slice.widget.SliceLiveData; - -import com.android.settings.R; -import com.android.settings.fuelgauge.batterytip.AppInfo; -import com.android.settings.fuelgauge.batterytip.BatteryTipLoader; -import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; -import com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip; -import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip; -import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip; -import com.android.settings.fuelgauge.batteryusage.BatteryUsageStatsLoader; -import com.android.settings.slices.SliceBackgroundWorker; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; -import org.robolectric.annotation.Config; -import org.robolectric.annotation.Implementation; -import org.robolectric.annotation.Implements; -import org.robolectric.annotation.Resetter; - -import java.util.ArrayList; -import java.util.List; - -@RunWith(RobolectricTestRunner.class) -@Config(shadows = { - BatteryFixSliceTest.ShadowBatteryUsageStatsLoader.class, - BatteryFixSliceTest.ShadowBatteryTipLoader.class -}) -public class BatteryFixSliceTest { - - private Context mContext; - private BatteryFixSlice mSlice; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - mContext = RuntimeEnvironment.application; - mSlice = new BatteryFixSlice(mContext); - - // Set-up specs for SliceMetadata. - SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS); - } - - @After - public void tearDown() { - ShadowBatteryTipLoader.reset(); - ShadowSliceBackgroundWorker.reset(); - ShadowEarlyWarningTip.reset(); - } - - @Test - public void refreshBatteryTips_hasImportantTip_shouldReturnTrue() { - final List tips = new ArrayList<>(); - tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false)); - tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false)); - ShadowBatteryTipLoader.setBatteryTips(tips); - - BatteryFixSlice.refreshBatteryTips(mContext); - - assertThat(BatteryFixSlice.isBatteryTipAvailableFromCache(mContext)).isTrue(); - } - - @Test - public void getSlice_unimportantSlice_shouldSkip() { - final List tips = new ArrayList<>(); - final List appList = new ArrayList<>(); - appList.add(new AppInfo.Builder() - .setPackageName("com.android.settings") - .setScreenOnTimeMs(10000L) - .build()); - tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false)); - tips.add(new EarlyWarningTip(BatteryTip.StateType.HANDLED, false)); - tips.add(new HighUsageTip(1000L, appList)); - ShadowBatteryTipLoader.setBatteryTips(tips); - - BatteryFixSlice.refreshBatteryTips(mContext); - final Slice slice = mSlice.getSlice(); - - assertThat(SliceMetadata.from(mContext, slice).isErrorSlice()).isTrue(); - } - - @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowEarlyWarningTip.class, - BatteryFixSliceTest.ShadowSliceBackgroundWorker.class - }) - public void getSlice_hasImportantTip_shouldTintIcon() { - final List tips = new ArrayList<>(); - tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false)); - // Create fake cache data - ShadowBatteryTipLoader.setBatteryTips(tips); - BatteryFixSlice.refreshBatteryTips(mContext); - // Create fake background worker data - BatteryFixSlice.BatteryTipWorker batteryTipWorker = mock( - BatteryFixSlice.BatteryTipWorker.class); - when(batteryTipWorker.getResults()).thenReturn(tips); - ShadowSliceBackgroundWorker.setBatteryTipWorkerWorker(batteryTipWorker); - - final Slice slice = mSlice.getSlice(); - - assertThat(ShadowEarlyWarningTip.isIconTintColorIdCalled()).isTrue(); - } - - @Implements(BatteryUsageStatsLoader.class) - public static class ShadowBatteryUsageStatsLoader { - - @Implementation - protected BatteryUsageStats loadInBackground() { - return null; - } - } - - @Implements(BatteryTipLoader.class) - public static class ShadowBatteryTipLoader { - - private static List sBatteryTips = new ArrayList<>(); - - @Resetter - public static void reset() { - sBatteryTips = new ArrayList<>(); - } - - @Implementation - protected List loadInBackground() { - return sBatteryTips; - } - - private static void setBatteryTips(List tips) { - sBatteryTips = tips; - } - } - - @Implements(SliceBackgroundWorker.class) - public static class ShadowSliceBackgroundWorker { - - private static BatteryFixSlice.BatteryTipWorker sBatteryTipWorkerWorker; - - @Resetter - public static void reset() { - sBatteryTipWorkerWorker = null; - } - - @Implementation - protected static T getInstance(Uri uri) { - return (T) sBatteryTipWorkerWorker; - } - - public static void setBatteryTipWorkerWorker(BatteryFixSlice.BatteryTipWorker worker) { - sBatteryTipWorkerWorker = worker; - } - } - - @Implements(EarlyWarningTip.class) - public static class ShadowEarlyWarningTip { - - private static boolean mIsGetIconTintColorIdCalled; - - @Resetter - public static void reset() { - mIsGetIconTintColorIdCalled = false; - } - - @Implementation - protected int getIconTintColorId() { - mIsGetIconTintColorIdCalled = true; - return R.color.battery_bad_color_light; - } - - public static boolean isIconTintColorIdCalled() { - return mIsGetIconTintColorIdCalled; - } - } -} From 9dca8c3ff77d900242306964335d277930ea08d5 Mon Sep 17 00:00:00 2001 From: Yi-Ling Chuang Date: Fri, 4 Nov 2022 10:03:25 +0800 Subject: [PATCH 08/20] Remove BatteryFixSlice as it's not used The BatteryFixSlice hasn't been used for a while, and it's introducing memory leaks due to a design change at the framework's end. Hence, remove it. Bug: 245385410 Test: robotests Change-Id: I517cab71a32613d5cb5fcd3beb991a24926a2902 (cherry picked from commit e3fcf1f08208d45821b95dc6fa64cd13f049fe84) Merged-In: I517cab71a32613d5cb5fcd3beb991a24926a2902 --- .../fuelgauge/BatteryBroadcastReceiver.java | 2 - .../SettingsContextualCardProvider.java | 7 - .../slices/BatteryFixSlice.java | 258 ------------------ .../settings/slices/CustomSliceRegistry.java | 13 - .../accounts/AvatarViewMixinTest.java | 2 - .../BatteryBroadcastReceiverTest.java | 20 -- .../SettingsHomepageActivityTest.java | 7 - .../ContextualCardManagerTest.java | 6 +- .../slices/BatteryFixSliceTest.java | 207 -------------- 9 files changed, 3 insertions(+), 519 deletions(-) delete mode 100644 src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java delete mode 100644 tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java diff --git a/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java index 436cde809a8..558e0bfb391 100644 --- a/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java +++ b/src/com/android/settings/fuelgauge/BatteryBroadcastReceiver.java @@ -28,7 +28,6 @@ import androidx.annotation.IntDef; import androidx.annotation.VisibleForTesting; import com.android.settings.Utils; -import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -135,6 +134,5 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver { mBatteryListener.onBatteryChanged(BatteryUpdateType.BATTERY_SAVER); } } - BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext); } } \ No newline at end of file diff --git a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java index 067fcf90e00..81142c20569 100644 --- a/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java +++ b/src/com/android/settings/homepage/contextualcards/SettingsContextualCardProvider.java @@ -50,12 +50,6 @@ public class SettingsContextualCardProvider extends ContextualCardProvider { .setCardName(CustomSliceRegistry.LOW_STORAGE_SLICE_URI.toString()) .setCardCategory(ContextualCard.Category.IMPORTANT) .build(); - final ContextualCard batteryFixCard = - ContextualCard.newBuilder() - .setSliceUri(CustomSliceRegistry.BATTERY_FIX_SLICE_URI.toString()) - .setCardName(CustomSliceRegistry.BATTERY_FIX_SLICE_URI.toString()) - .setCardCategory(ContextualCard.Category.IMPORTANT) - .build(); final String contextualAdaptiveSleepSliceUri = CustomSliceRegistry.CONTEXTUAL_ADAPTIVE_SLEEP_URI.toString(); final ContextualCard contextualAdaptiveSleepCard = @@ -80,7 +74,6 @@ public class SettingsContextualCardProvider extends ContextualCardProvider { .addCard(wifiCard) .addCard(connectedDeviceCard) .addCard(lowStorageCard) - .addCard(batteryFixCard) .addCard(contextualAdaptiveSleepCard) .addCard(contextualFaceSettingsCard) .addCard(darkThemeCard) diff --git a/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java b/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java deleted file mode 100644 index 33dcd4e7972..00000000000 --- a/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright (C) 2018 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.homepage.contextualcards.slices; - -import static android.content.Context.MODE_PRIVATE; - -import static com.android.settings.slices.CustomSliceRegistry.BATTERY_FIX_SLICE_URI; - -import android.app.PendingIntent; -import android.app.settings.SettingsEnums; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffColorFilter; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.os.BatteryUsageStats; -import android.util.ArrayMap; -import android.view.View; - -import androidx.annotation.VisibleForTesting; -import androidx.annotation.WorkerThread; -import androidx.core.graphics.drawable.IconCompat; -import androidx.slice.Slice; -import androidx.slice.builders.ListBuilder; -import androidx.slice.builders.ListBuilder.RowBuilder; -import androidx.slice.builders.SliceAction; - -import com.android.settings.R; -import com.android.settings.SubSettings; -import com.android.settings.Utils; -import com.android.settings.fuelgauge.batterytip.BatteryTipLoader; -import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController; -import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; -import com.android.settings.fuelgauge.batteryusage.BatteryUsageStatsLoader; -import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary; -import com.android.settings.slices.CustomSliceable; -import com.android.settings.slices.SliceBackgroundWorker; -import com.android.settings.slices.SliceBuilderUtils; -import com.android.settingslib.utils.ThreadUtils; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -public class BatteryFixSlice implements CustomSliceable { - - @VisibleForTesting - static final String PREFS = "battery_fix_prefs"; - @VisibleForTesting - static final String KEY_CURRENT_TIPS_TYPE = "current_tip_type"; - static final String KEY_CURRENT_TIPS_STATE = "current_tip_state"; - - // A map tracking which BatteryTip and which state of that tip is not important. - private static final Map> UNIMPORTANT_BATTERY_TIPS; - - static { - UNIMPORTANT_BATTERY_TIPS = new ArrayMap<>(); - UNIMPORTANT_BATTERY_TIPS.put(BatteryTip.TipType.SUMMARY, - Arrays.asList(BatteryTip.StateType.NEW, BatteryTip.StateType.HANDLED)); - UNIMPORTANT_BATTERY_TIPS.put(BatteryTip.TipType.HIGH_DEVICE_USAGE, - Arrays.asList(BatteryTip.StateType.NEW, BatteryTip.StateType.HANDLED)); - UNIMPORTANT_BATTERY_TIPS.put(BatteryTip.TipType.BATTERY_SAVER, - Arrays.asList(BatteryTip.StateType.HANDLED)); - } - - private static final String TAG = "BatteryFixSlice"; - - private final Context mContext; - - public BatteryFixSlice(Context context) { - mContext = context; - } - - @Override - public Uri getUri() { - return BATTERY_FIX_SLICE_URI; - } - - @Override - public Slice getSlice() { - final ListBuilder sliceBuilder = - new ListBuilder(mContext, BATTERY_FIX_SLICE_URI, ListBuilder.INFINITY) - .setAccentColor(COLOR_NOT_TINTED); - - if (!isBatteryTipAvailableFromCache(mContext)) { - return buildBatteryGoodSlice(sliceBuilder, true /* isError */); - } - - final SliceBackgroundWorker worker = SliceBackgroundWorker.getInstance(getUri()); - final List batteryTips = worker != null ? worker.getResults() : null; - - if (batteryTips == null) { - // Because we need wait slice background worker return data - return buildBatteryGoodSlice(sliceBuilder, false /* isError */); - } - - for (BatteryTip batteryTip : batteryTips) { - if (batteryTip.getState() == BatteryTip.StateType.INVISIBLE) { - continue; - } - final Drawable drawable = mContext.getDrawable(batteryTip.getIconId()); - final int iconTintColorId = batteryTip.getIconTintColorId(); - if (iconTintColorId != View.NO_ID) { - drawable.setColorFilter(new PorterDuffColorFilter( - mContext.getResources().getColor(iconTintColorId), - PorterDuff.Mode.SRC_IN)); - } - - final IconCompat icon = Utils.createIconWithDrawable(drawable); - final SliceAction primaryAction = SliceAction.createDeeplink(getPrimaryAction(), - icon, - ListBuilder.ICON_IMAGE, - batteryTip.getTitle(mContext)); - sliceBuilder.addRow(new RowBuilder() - .setTitleItem(icon, ListBuilder.ICON_IMAGE) - .setTitle(batteryTip.getTitle(mContext)) - .setSubtitle(batteryTip.getSummary(mContext)) - .setPrimaryAction(primaryAction)); - break; - } - return sliceBuilder.build(); - } - - @Override - public Intent getIntent() { - final String screenTitle = mContext.getText(R.string.power_usage_summary_title) - .toString(); - final Uri contentUri = new Uri.Builder() - .appendPath(BatteryTipPreferenceController.PREF_NAME).build(); - - return SliceBuilderUtils.buildSearchResultPageIntent(mContext, - PowerUsageSummary.class.getName(), BatteryTipPreferenceController.PREF_NAME, - screenTitle, - SettingsEnums.SLICE, - this) - .setClassName(mContext.getPackageName(), SubSettings.class.getName()) - .setData(contentUri); - } - - @Override - public int getSliceHighlightMenuRes() { - return R.string.menu_key_battery; - } - - @Override - public void onNotifyChange(Intent intent) { - } - - @Override - public Class getBackgroundWorkerClass() { - return BatteryTipWorker.class; - } - - private PendingIntent getPrimaryAction() { - final Intent intent = getIntent(); - return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, - PendingIntent.FLAG_IMMUTABLE); - } - - private Slice buildBatteryGoodSlice(ListBuilder sliceBuilder, boolean isError) { - final IconCompat icon = IconCompat.createWithResource(mContext, - R.drawable.ic_battery_status_good_24dp); - final String title = mContext.getString(R.string.power_usage_summary_title); - final SliceAction primaryAction = SliceAction.createDeeplink(getPrimaryAction(), icon, - ListBuilder.ICON_IMAGE, title); - sliceBuilder.addRow(new RowBuilder() - .setTitleItem(icon, ListBuilder.ICON_IMAGE) - .setTitle(title) - .setPrimaryAction(primaryAction)) - .setIsError(isError); - return sliceBuilder.build(); - } - - // TODO(b/114807643): we should find a better way to get current battery tip type quickly - // Now we save battery tip type to shared preference when battery level changes - public static void updateBatteryTipAvailabilityCache(Context context) { - ThreadUtils.postOnBackgroundThread(() -> refreshBatteryTips(context)); - } - - - @VisibleForTesting - static boolean isBatteryTipAvailableFromCache(Context context) { - final SharedPreferences prefs = context.getSharedPreferences(PREFS, MODE_PRIVATE); - - final int type = prefs.getInt(KEY_CURRENT_TIPS_TYPE, BatteryTip.TipType.SUMMARY); - final int state = prefs.getInt(KEY_CURRENT_TIPS_STATE, BatteryTip.StateType.INVISIBLE); - if (state == BatteryTip.StateType.INVISIBLE) { - // State is INVISIBLE, We should not show anything. - return false; - } - final boolean unimportant = UNIMPORTANT_BATTERY_TIPS.containsKey(type) - && UNIMPORTANT_BATTERY_TIPS.get(type).contains(state); - return !unimportant; - } - - @WorkerThread - @VisibleForTesting - static List refreshBatteryTips(Context context) { - final BatteryUsageStatsLoader statsLoader = new BatteryUsageStatsLoader(context, - /* includeBatteryHistory */ false); - final BatteryUsageStats batteryUsageStats = statsLoader.loadInBackground(); - final BatteryTipLoader loader = new BatteryTipLoader(context, batteryUsageStats); - final List batteryTips = loader.loadInBackground(); - for (BatteryTip batteryTip : batteryTips) { - if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) { - context.getSharedPreferences(PREFS, MODE_PRIVATE) - .edit() - .putInt(KEY_CURRENT_TIPS_TYPE, batteryTip.getType()) - .putInt(KEY_CURRENT_TIPS_STATE, batteryTip.getState()) - .apply(); - break; - } - } - return batteryTips; - } - - public static class BatteryTipWorker extends SliceBackgroundWorker { - - private final Context mContext; - - public BatteryTipWorker(Context context, Uri uri) { - super(context, uri); - mContext = context; - } - - @Override - protected void onSlicePinned() { - ThreadUtils.postOnBackgroundThread(() -> { - final List batteryTips = refreshBatteryTips(mContext); - updateResults(batteryTips); - }); - } - - @Override - protected void onSliceUnpinned() { - } - - @Override - public void close() { - } - } -} diff --git a/src/com/android/settings/slices/CustomSliceRegistry.java b/src/com/android/settings/slices/CustomSliceRegistry.java index 1cc3276f1ce..217c1e963be 100644 --- a/src/com/android/settings/slices/CustomSliceRegistry.java +++ b/src/com/android/settings/slices/CustomSliceRegistry.java @@ -29,8 +29,6 @@ import androidx.annotation.VisibleForTesting; import com.android.settings.display.AlwaysOnDisplaySlice; import com.android.settings.display.ScreenTimeoutPreferenceController; import com.android.settings.flashlight.FlashlightSlice; -import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController; -import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice; import com.android.settings.homepage.contextualcards.slices.BluetoothDevicesSlice; import com.android.settings.homepage.contextualcards.slices.ContextualAdaptiveSleepSlice; import com.android.settings.homepage.contextualcards.slices.DarkThemeSlice; @@ -64,16 +62,6 @@ public class CustomSliceRegistry { .appendPath(ScreenTimeoutPreferenceController.PREF_NAME) .build(); - /** - * Uri for Battery Fix Slice. - */ - public static final Uri BATTERY_FIX_SLICE_URI = new Uri.Builder() - .scheme(ContentResolver.SCHEME_CONTENT) - .authority(SettingsSliceProvider.SLICE_AUTHORITY) - .appendEncodedPath(SettingsSlicesContract.PATH_SETTING_INTENT) - .appendPath(BatteryTipPreferenceController.PREF_NAME) - .build(); - /** * Backing Uri for the Bluetooth Slice. */ @@ -332,7 +320,6 @@ public class CustomSliceRegistry { // Slices for contextual card. sUriToSlice.put(FACE_ENROLL_SLICE_URI, FaceSetupSlice.class); - sUriToSlice.put(BATTERY_FIX_SLICE_URI, BatteryFixSlice.class); sUriToSlice.put(CONTEXTUAL_ADAPTIVE_SLEEP_URI, ContextualAdaptiveSleepSlice.class); sUriToSlice.put(CONTEXTUAL_WIFI_SLICE_URI, ContextualWifiSlice.class); sUriToSlice.put(LOW_STORAGE_SLICE_URI, LowStorageSlice.class); diff --git a/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java b/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java index 04db5270ec7..61017f71ee0 100644 --- a/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java +++ b/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java @@ -41,7 +41,6 @@ import android.os.Bundle; import android.widget.ImageView; import com.android.settings.homepage.SettingsHomepageActivity; -import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest; import com.android.settings.testutils.shadow.ShadowUserManager; import org.junit.Before; @@ -95,7 +94,6 @@ public class AvatarViewMixinTest { } @Test - @Config(shadows = BatteryFixSliceTest.ShadowBatteryTipLoader.class) public void onStart_useMockAvatarViewMixin_shouldBeExecuted() { final AvatarViewMixin mockAvatar = spy(new AvatarViewMixin(mActivity, mImageView)); diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java index d4469301894..867d8f44b7e 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryBroadcastReceiverTest.java @@ -33,7 +33,6 @@ import android.os.BatteryManager; import android.os.PowerManager; import com.android.settings.Utils; -import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest; import org.junit.Before; import org.junit.Test; @@ -42,7 +41,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; -import org.robolectric.annotation.Config; @RunWith(RobolectricTestRunner.class) public class BatteryBroadcastReceiverTest { @@ -77,9 +75,6 @@ public class BatteryBroadcastReceiverTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void testOnReceive_batteryLevelChanged_dataUpdated() { mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent); @@ -91,9 +86,6 @@ public class BatteryBroadcastReceiverTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void testOnReceive_batteryHealthChanged_dataUpdated() { mChargingIntent .putExtra(BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_OVERHEAT); @@ -105,9 +97,6 @@ public class BatteryBroadcastReceiverTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void onReceive_batteryNotPresent_shouldShowHelpMessage() { mChargingIntent.putExtra(BatteryManager.EXTRA_PRESENT, false); @@ -117,9 +106,6 @@ public class BatteryBroadcastReceiverTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void testOnReceive_powerSaveModeChanged_listenerInvoked() { mBatteryBroadcastReceiver.onReceive(mContext, new Intent(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)); @@ -128,9 +114,6 @@ public class BatteryBroadcastReceiverTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void testOnReceive_batteryDataNotChanged_listenerNotInvoked() { final String batteryLevel = Utils.getBatteryPercentage(mChargingIntent); final String batteryStatus = @@ -148,9 +131,6 @@ public class BatteryBroadcastReceiverTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void testRegister_updateBatteryStatus() { doReturn(mChargingIntent).when(mContext).registerReceiver(any(), any()); diff --git a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java index b3feef413fe..719ce289971 100644 --- a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java +++ b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java @@ -38,7 +38,6 @@ import androidx.fragment.app.Fragment; import com.android.settings.R; import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl; -import com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest; import com.android.settings.testutils.shadow.ShadowActivityEmbeddingUtils; import com.android.settings.testutils.shadow.ShadowUserManager; import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin; @@ -150,9 +149,6 @@ public class SettingsHomepageActivityTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class - }) public void onStart_isNotDebuggable_shouldHideSystemOverlay() { ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false); @@ -169,9 +165,6 @@ public class SettingsHomepageActivityTest { } @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowBatteryTipLoader.class, - }) public void onStop_isNotDebuggable_shouldRemoveHideSystemOverlay() { ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false); diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java index 69333d7ad9d..f18d94f828b 100644 --- a/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java +++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/ContextualCardManagerTest.java @@ -135,7 +135,7 @@ public class ContextualCardManagerTest { final List actualCards = mManager.mSavedCards.stream().collect(Collectors.toList()); final List expectedCards = Arrays.asList("test_low_storage", "test_flashlight", - "test_dark_theme", "test_gesture", "test_battery"); + "test_dark_theme", "test_gesture", "test_face_enroll"); assertThat(actualCards).containsExactlyElementsIn(expectedCards); } @@ -695,9 +695,9 @@ public class ContextualCardManagerTest { .setViewType(VIEW_TYPE_FULL_WIDTH) .build()); cards.add(new ContextualCard.Builder() - .setName("test_battery") + .setName("test_face_enroll") .setCardType(ContextualCard.CardType.SLICE) - .setSliceUri(CustomSliceRegistry.BATTERY_FIX_SLICE_URI) + .setSliceUri(CustomSliceRegistry.FACE_ENROLL_SLICE_URI) .setViewType(VIEW_TYPE_FULL_WIDTH) .build()); return cards; diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java deleted file mode 100644 index 78541db4947..00000000000 --- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSliceTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) 2018 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.homepage.contextualcards.slices; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import android.content.Context; -import android.net.Uri; -import android.os.BatteryUsageStats; - -import androidx.slice.Slice; -import androidx.slice.SliceMetadata; -import androidx.slice.SliceProvider; -import androidx.slice.widget.SliceLiveData; - -import com.android.settings.R; -import com.android.settings.fuelgauge.batterytip.AppInfo; -import com.android.settings.fuelgauge.batterytip.BatteryTipLoader; -import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; -import com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip; -import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip; -import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip; -import com.android.settings.fuelgauge.batteryusage.BatteryUsageStatsLoader; -import com.android.settings.slices.SliceBackgroundWorker; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; -import org.robolectric.annotation.Config; -import org.robolectric.annotation.Implementation; -import org.robolectric.annotation.Implements; -import org.robolectric.annotation.Resetter; - -import java.util.ArrayList; -import java.util.List; - -@RunWith(RobolectricTestRunner.class) -@Config(shadows = { - BatteryFixSliceTest.ShadowBatteryUsageStatsLoader.class, - BatteryFixSliceTest.ShadowBatteryTipLoader.class -}) -public class BatteryFixSliceTest { - - private Context mContext; - private BatteryFixSlice mSlice; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - mContext = RuntimeEnvironment.application; - mSlice = new BatteryFixSlice(mContext); - - // Set-up specs for SliceMetadata. - SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS); - } - - @After - public void tearDown() { - ShadowBatteryTipLoader.reset(); - ShadowSliceBackgroundWorker.reset(); - ShadowEarlyWarningTip.reset(); - } - - @Test - public void refreshBatteryTips_hasImportantTip_shouldReturnTrue() { - final List tips = new ArrayList<>(); - tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false)); - tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false)); - ShadowBatteryTipLoader.setBatteryTips(tips); - - BatteryFixSlice.refreshBatteryTips(mContext); - - assertThat(BatteryFixSlice.isBatteryTipAvailableFromCache(mContext)).isTrue(); - } - - @Test - public void getSlice_unimportantSlice_shouldSkip() { - final List tips = new ArrayList<>(); - final List appList = new ArrayList<>(); - appList.add(new AppInfo.Builder() - .setPackageName("com.android.settings") - .setScreenOnTimeMs(10000L) - .build()); - tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false)); - tips.add(new EarlyWarningTip(BatteryTip.StateType.HANDLED, false)); - tips.add(new HighUsageTip(1000L, appList)); - ShadowBatteryTipLoader.setBatteryTips(tips); - - BatteryFixSlice.refreshBatteryTips(mContext); - final Slice slice = mSlice.getSlice(); - - assertThat(SliceMetadata.from(mContext, slice).isErrorSlice()).isTrue(); - } - - @Test - @Config(shadows = { - BatteryFixSliceTest.ShadowEarlyWarningTip.class, - BatteryFixSliceTest.ShadowSliceBackgroundWorker.class - }) - public void getSlice_hasImportantTip_shouldTintIcon() { - final List tips = new ArrayList<>(); - tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false)); - // Create fake cache data - ShadowBatteryTipLoader.setBatteryTips(tips); - BatteryFixSlice.refreshBatteryTips(mContext); - // Create fake background worker data - BatteryFixSlice.BatteryTipWorker batteryTipWorker = mock( - BatteryFixSlice.BatteryTipWorker.class); - when(batteryTipWorker.getResults()).thenReturn(tips); - ShadowSliceBackgroundWorker.setBatteryTipWorkerWorker(batteryTipWorker); - - final Slice slice = mSlice.getSlice(); - - assertThat(ShadowEarlyWarningTip.isIconTintColorIdCalled()).isTrue(); - } - - @Implements(BatteryUsageStatsLoader.class) - public static class ShadowBatteryUsageStatsLoader { - - @Implementation - protected BatteryUsageStats loadInBackground() { - return null; - } - } - - @Implements(BatteryTipLoader.class) - public static class ShadowBatteryTipLoader { - - private static List sBatteryTips = new ArrayList<>(); - - @Resetter - public static void reset() { - sBatteryTips = new ArrayList<>(); - } - - @Implementation - protected List loadInBackground() { - return sBatteryTips; - } - - private static void setBatteryTips(List tips) { - sBatteryTips = tips; - } - } - - @Implements(SliceBackgroundWorker.class) - public static class ShadowSliceBackgroundWorker { - - private static BatteryFixSlice.BatteryTipWorker sBatteryTipWorkerWorker; - - @Resetter - public static void reset() { - sBatteryTipWorkerWorker = null; - } - - @Implementation - protected static T getInstance(Uri uri) { - return (T) sBatteryTipWorkerWorker; - } - - public static void setBatteryTipWorkerWorker(BatteryFixSlice.BatteryTipWorker worker) { - sBatteryTipWorkerWorker = worker; - } - } - - @Implements(EarlyWarningTip.class) - public static class ShadowEarlyWarningTip { - - private static boolean mIsGetIconTintColorIdCalled; - - @Resetter - public static void reset() { - mIsGetIconTintColorIdCalled = false; - } - - @Implementation - protected int getIconTintColorId() { - mIsGetIconTintColorIdCalled = true; - return R.color.battery_bad_color_light; - } - - public static boolean isIconTintColorIdCalled() { - return mIsGetIconTintColorIdCalled; - } - } -} From 0229a6890c9ad7899c2965fc763eefeac5612d74 Mon Sep 17 00:00:00 2001 From: Tyler Freeman Date: Thu, 1 Dec 2022 19:49:43 +0000 Subject: [PATCH 09/20] Revert "feat(non linear font scaling): support up to 200% font s..." Revert submission 20003379-fontscaling Reason for revert: Causing SysUi crash b/260984829 Reverted Changes: I8d4131cb0:feat(non linear font scaling): add CTS test to ver... I17d67252b:feat(non linear font scaling)!: add FontScaleConve... Ie8d5495d4:feat(non linear font scaling): support up to 200% ... Change-Id: I2878836625566a6ee1ff2f67be6f1f5d6f0f8feb (cherry picked from commit f5004e49d899c12c27da1b048f0ac991095fca54) Merged-In: I2878836625566a6ee1ff2f67be6f1f5d6f0f8feb --- res/values/arrays.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 46114cbe11d..d5aa26705f7 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -105,16 +105,11 @@ 1800000 - 0.85 1.0 1.15 1.30 - 1.50 - 1.80 - 2.0 From 27638289b2c474131b5e0c571c0d906f17321141 Mon Sep 17 00:00:00 2001 From: Marcelo Arteiro Date: Thu, 9 Mar 2023 23:40:40 +0000 Subject: [PATCH 10/20] Revert "Automated Token Alignment Android/Material" This reverts commit c9ca4a90147eada543278b6497d08b3aeecfda58. Reason for revert: Black Search Box in Settings App (Light Theme) Change-Id: I936e977ce044b8da41d818d6b3392adc6fd1e4e6 (cherry picked from commit on googleplex-android-review.googlesource.com host: 1b599e02322de0f826e0688d825b94700a875668) Merged-In: I936e977ce044b8da41d818d6b3392adc6fd1e4e6 --- res/color/dream_card_color_state_list.xml | 2 +- res/color/dream_card_icon_color_state_list.xml | 4 ++-- res/color/dream_card_text_color_state_list.xml | 2 +- res/drawable/accessibility_text_reading_preview.xml | 2 +- res/drawable/broadcast_button_outline.xml | 2 +- res/drawable/button_border_selected.xml | 2 +- res/drawable/dream_preview_rounded_bg.xml | 2 +- res/drawable/ic_check_24dp.xml | 2 +- res/drawable/ic_check_circle_filled_24dp.xml | 2 +- res/drawable/ic_modifier_keys_reset.xml | 2 +- res/drawable/modifier_key_bordered.xml | 2 +- res/drawable/modifier_key_lisetview_background.xml | 2 +- res/drawable/rounded_bg.xml | 2 +- res/drawable/sim_confirm_dialog_btn_outline.xml | 2 +- res/drawable/user_select_background.xml | 4 ++-- res/drawable/volume_dialog_button_background_outline.xml | 2 +- res/layout/dream_preview_button.xml | 2 +- res/layout/modifier_key_item.xml | 2 +- res/layout/modifier_key_picker_dialog.xml | 2 +- res/layout/qrcode_scanner_fragment.xml | 2 +- res/layout/trackpad_gesture_preview.xml | 4 ++-- res/values-night/colors.xml | 2 +- res/values/colors.xml | 4 ++-- res/values/styles.xml | 2 +- .../settings/dashboard/profileselector/UserAdapter.java | 2 +- .../settings/fuelgauge/batteryusage/BatteryChartView.java | 2 +- .../inputmethod/ModifierKeysPickerDialogFragment.java | 2 +- .../inputmethod/ModifierKeysPreferenceController.java | 2 +- .../inputmethod/ModifierKeysRestorePreferenceController.java | 2 +- 29 files changed, 33 insertions(+), 33 deletions(-) diff --git a/res/color/dream_card_color_state_list.xml b/res/color/dream_card_color_state_list.xml index eae3fe46a6d..b0c86bba121 100644 --- a/res/color/dream_card_color_state_list.xml +++ b/res/color/dream_card_color_state_list.xml @@ -18,5 +18,5 @@ - + \ No newline at end of file diff --git a/res/color/dream_card_icon_color_state_list.xml b/res/color/dream_card_icon_color_state_list.xml index a91ae3d3be3..c2e32cba34b 100644 --- a/res/color/dream_card_icon_color_state_list.xml +++ b/res/color/dream_card_icon_color_state_list.xml @@ -17,6 +17,6 @@ - - + + \ No newline at end of file diff --git a/res/color/dream_card_text_color_state_list.xml b/res/color/dream_card_text_color_state_list.xml index bd1f16578ea..438855fd233 100644 --- a/res/color/dream_card_text_color_state_list.xml +++ b/res/color/dream_card_text_color_state_list.xml @@ -17,6 +17,6 @@ - + \ No newline at end of file diff --git a/res/drawable/accessibility_text_reading_preview.xml b/res/drawable/accessibility_text_reading_preview.xml index 040ccdfba3c..54f3a428915 100644 --- a/res/drawable/accessibility_text_reading_preview.xml +++ b/res/drawable/accessibility_text_reading_preview.xml @@ -20,5 +20,5 @@ android:shape="rectangle"> - + diff --git a/res/drawable/broadcast_button_outline.xml b/res/drawable/broadcast_button_outline.xml index c8658a9fccd..6609915dd74 100644 --- a/res/drawable/broadcast_button_outline.xml +++ b/res/drawable/broadcast_button_outline.xml @@ -29,7 +29,7 @@ - + android:color="?androidprv:attr/colorSurface" /> diff --git a/res/drawable/dream_preview_rounded_bg.xml b/res/drawable/dream_preview_rounded_bg.xml index 2aae26b2ad2..4da0c7c1a75 100644 --- a/res/drawable/dream_preview_rounded_bg.xml +++ b/res/drawable/dream_preview_rounded_bg.xml @@ -17,6 +17,6 @@ - + \ No newline at end of file diff --git a/res/drawable/ic_check_24dp.xml b/res/drawable/ic_check_24dp.xml index 9ac80215bb0..5801e701e0a 100644 --- a/res/drawable/ic_check_24dp.xml +++ b/res/drawable/ic_check_24dp.xml @@ -18,7 +18,7 @@ android:height="24dp" android:viewportWidth="24.0" android:viewportHeight="24.0" - android:tint="?androidprv:attr/materialColorPrimaryContainer"> + android:tint="?androidprv:attr/colorAccentPrimaryVariant"> diff --git a/res/drawable/ic_check_circle_filled_24dp.xml b/res/drawable/ic_check_circle_filled_24dp.xml index 9d2e296ef2f..8e1f1e7f0dc 100644 --- a/res/drawable/ic_check_circle_filled_24dp.xml +++ b/res/drawable/ic_check_circle_filled_24dp.xml @@ -20,7 +20,7 @@ android:height="24dp" android:viewportWidth="24" android:viewportHeight="24" - android:tint="?androidprv:attr/materialColorPrimaryContainer"> + android:tint="?androidprv:attr/colorAccentPrimaryVariant"> diff --git a/res/drawable/ic_modifier_keys_reset.xml b/res/drawable/ic_modifier_keys_reset.xml index 7758be8cd2e..a8cc1984c94 100644 --- a/res/drawable/ic_modifier_keys_reset.xml +++ b/res/drawable/ic_modifier_keys_reset.xml @@ -21,7 +21,7 @@ android:height="24.0dp" android:viewportWidth="24.0" android:viewportHeight="24.0" - android:tint="?androidprv:attr/materialColorPrimaryContainer"> + android:tint="?androidprv:attr/colorAccentPrimaryVariant"> diff --git a/res/drawable/modifier_key_bordered.xml b/res/drawable/modifier_key_bordered.xml index 976a3ebb404..17f0090a678 100644 --- a/res/drawable/modifier_key_bordered.xml +++ b/res/drawable/modifier_key_bordered.xml @@ -25,7 +25,7 @@ + android:color="?androidprv:attr/colorAccentPrimaryVariant"/> diff --git a/res/drawable/modifier_key_lisetview_background.xml b/res/drawable/modifier_key_lisetview_background.xml index 4e12b626b71..b65c61ee122 100644 --- a/res/drawable/modifier_key_lisetview_background.xml +++ b/res/drawable/modifier_key_lisetview_background.xml @@ -22,7 +22,7 @@ - + diff --git a/res/drawable/rounded_bg.xml b/res/drawable/rounded_bg.xml index ae12af895dc..3e4e91bafea 100644 --- a/res/drawable/rounded_bg.xml +++ b/res/drawable/rounded_bg.xml @@ -17,7 +17,7 @@ - + - - + - + diff --git a/res/drawable/volume_dialog_button_background_outline.xml b/res/drawable/volume_dialog_button_background_outline.xml index 36ffb93f7a4..efbaec63bd5 100644 --- a/res/drawable/volume_dialog_button_background_outline.xml +++ b/res/drawable/volume_dialog_button_background_outline.xml @@ -21,7 +21,7 @@ diff --git a/res/layout/modifier_key_item.xml b/res/layout/modifier_key_item.xml index 51ba0275293..7bd344c8bb2 100644 --- a/res/layout/modifier_key_item.xml +++ b/res/layout/modifier_key_item.xml @@ -32,7 +32,7 @@ android:ellipsize="marquee" android:fadingEdge="horizontal" android:src="@drawable/ic_check_24dp" - android:tint="?androidprv:attr/materialColorPrimaryContainer"/> + android:tint="?androidprv:attr/colorAccentPrimaryVariant"/> diff --git a/res/layout/qrcode_scanner_fragment.xml b/res/layout/qrcode_scanner_fragment.xml index e6d1c32bfe4..ee602dba530 100644 --- a/res/layout/qrcode_scanner_fragment.xml +++ b/res/layout/qrcode_scanner_fragment.xml @@ -35,7 +35,7 @@ android:orientation="vertical"> diff --git a/res/layout/trackpad_gesture_preview.xml b/res/layout/trackpad_gesture_preview.xml index be2b6a00608..aa227be8019 100644 --- a/res/layout/trackpad_gesture_preview.xml +++ b/res/layout/trackpad_gesture_preview.xml @@ -81,7 +81,7 @@ android:paddingVertical="14dp" android:drawablePadding="9dp" style="@style/ModifierKeyButtonDone" - android:textColor="?androidprv:attr/materialColorOnPrimary" + android:textColor="?androidprv:attr/textColorOnAccent" android:text="@string/gesture_button_next"/>