diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-05-15 23:35:06 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-05-15 23:35:06 +0000 |
commit | 4bbe564aeaf1f3403581bfe18418b0fc972a26de (patch) | |
tree | 3125a5908d2a9a1dd9132fb58630f7a17afeb444 /src/com/android/settings | |
parent | a2641574382e756702bc906ca3af7f8792c76273 (diff) | |
parent | cd237ccf9b53fb9856ca4361201640ba16839306 (diff) | |
download | packages_apps_Settings-4bbe564aeaf1f3403581bfe18418b0fc972a26de.tar.gz packages_apps_Settings-4bbe564aeaf1f3403581bfe18418b0fc972a26de.tar.bz2 packages_apps_Settings-4bbe564aeaf1f3403581bfe18418b0fc972a26de.zip |
Merge changes from topic "jr-update" into rvc-dev
* changes:
Update conversation launch point
Add settings for apps that don't use full conversations
Diffstat (limited to 'src/com/android/settings')
7 files changed, 215 insertions, 19 deletions
diff --git a/src/com/android/settings/notification/ConversationListSummaryPreferenceController.java b/src/com/android/settings/notification/ConversationListSummaryPreferenceController.java new file mode 100644 index 0000000000..5d7ea205d0 --- /dev/null +++ b/src/com/android/settings/notification/ConversationListSummaryPreferenceController.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2020 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.notification; + +import android.content.Context; + +import com.android.settings.R; +import com.android.settings.core.BasePreferenceController; + +public class ConversationListSummaryPreferenceController extends BasePreferenceController { + + private NotificationBackend mBackend; + + public ConversationListSummaryPreferenceController(Context context, String key) { + super(context, key); + mBackend = new NotificationBackend(); + } + + @Override + public int getAvailabilityStatus() { + return AVAILABLE; + } + + @Override + public CharSequence getSummary() { + final int count = mBackend.getConversations(true).getList().size(); + if (count == 0) { + return mContext.getText(R.string.priority_conversation_count_zero); + } + return mContext.getResources().getQuantityString( + R.plurals.priority_conversation_count, + count, count); + } + + void setBackend(NotificationBackend backend) { + mBackend = backend; + } +} diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java index 6172268bd0..83df3239d3 100644 --- a/src/com/android/settings/notification/NotificationBackend.java +++ b/src/com/android/settings/notification/NotificationBackend.java @@ -268,15 +268,32 @@ public class NotificationBackend { } } - public boolean hasSentMessage(String pkg, int uid) { + public boolean isInInvalidMsgState(String pkg, int uid) { try { - return sINM.hasSentMessage(pkg, uid); + return sINM.isInInvalidMsgState(pkg, uid); } catch (Exception e) { Log.w(TAG, "Error calling NoMan", e); return false; } } + public boolean hasUserDemotedInvalidMsgApp(String pkg, int uid) { + try { + return sINM.hasUserDemotedInvalidMsgApp(pkg, uid); + } catch (Exception e) { + Log.w(TAG, "Error calling NoMan", e); + return false; + } + } + + public void setInvalidMsgAppDemoted(String pkg, int uid, boolean isDemoted) { + try { + sINM.setInvalidMsgAppDemoted(pkg, uid, isDemoted); + } catch (Exception e) { + Log.w(TAG, "Error calling NoMan", e); + } + } + /** * Returns all notification channels associated with the package and uid that will bypass DND */ diff --git a/src/com/android/settings/notification/app/AppConversationListPreferenceController.java b/src/com/android/settings/notification/app/AppConversationListPreferenceController.java index 2fcd2b2059..0ba943605a 100644 --- a/src/com/android/settings/notification/app/AppConversationListPreferenceController.java +++ b/src/com/android/settings/notification/app/AppConversationListPreferenceController.java @@ -46,7 +46,7 @@ public class AppConversationListPreferenceController extends NotificationPrefere protected List<ConversationChannelWrapper> mConversations = new ArrayList<>(); protected PreferenceCategory mPreference; - private boolean mHasSentMsg; + private boolean mIsInInvalidMsgState; public AppConversationListPreferenceController(Context context, NotificationBackend backend) { super(context, backend); @@ -88,7 +88,7 @@ public class AppConversationListPreferenceController extends NotificationPrefere new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... unused) { - mHasSentMsg = mBackend.hasSentMessage(mAppRow.pkg, mAppRow.uid); + mIsInInvalidMsgState = mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid); ParceledListSlice<ConversationChannelWrapper> list = mBackend.getConversations(mAppRow.pkg, mAppRow.uid); if (list != null) { @@ -121,20 +121,10 @@ public class AppConversationListPreferenceController extends NotificationPrefere if (mPreference == null) { return; } - // TODO: if preference has children, compare with newly loaded list - mPreference.removeAll(); - if (mConversations.isEmpty()) { - if (mHasSentMsg) { - mPreference.setVisible(true); - Preference notSupportedPref = new Preference(mContext); - notSupportedPref.setSummary(mContext.getString( - R.string.convo_not_supported_summary, mAppRow.label)); - mPreference.addPreference(notSupportedPref); - } else { - mPreference.setVisible(false); - } - } else { - mPreference.setVisible(true); + + if (!mIsInInvalidMsgState && !mConversations.isEmpty()) { + // TODO: if preference has children, compare with newly loaded list + mPreference.removeAll(); mPreference.setTitle(getTitleResId()); populateConversations(); } diff --git a/src/com/android/settings/notification/app/AppNotificationSettings.java b/src/com/android/settings/notification/app/AppNotificationSettings.java index a4228411a7..58c18bae43 100644 --- a/src/com/android/settings/notification/app/AppNotificationSettings.java +++ b/src/com/android/settings/notification/app/AppNotificationSettings.java @@ -122,6 +122,8 @@ public class AppNotificationSettings extends NotificationSettings { mControllers.add(new DeletedChannelsPreferenceController(context, mBackend)); mControllers.add(new ChannelListPreferenceController(context, mBackend)); mControllers.add(new AppConversationListPreferenceController(context, mBackend)); + mControllers.add(new InvalidConversationInfoPreferenceController(context, mBackend)); + mControllers.add(new InvalidConversationPreferenceController(context, mBackend)); mControllers.add(new BubbleSummaryPreferenceController(context, mBackend)); return new ArrayList<>(mControllers); } diff --git a/src/com/android/settings/notification/app/BubblePreferenceController.java b/src/com/android/settings/notification/app/BubblePreferenceController.java index 0ca2095d6e..1aed15609c 100644 --- a/src/com/android/settings/notification/app/BubblePreferenceController.java +++ b/src/com/android/settings/notification/app/BubblePreferenceController.java @@ -86,7 +86,7 @@ public class BubblePreferenceController extends NotificationPreferenceController @Override public void updateState(Preference preference) { if (mIsAppPage && mAppRow != null) { - mHasSentInvalidMsg = mBackend.hasSentMessage(mAppRow.pkg, mAppRow.uid); + mHasSentInvalidMsg = mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid); mNumConversations = mBackend.getConversations( mAppRow.pkg, mAppRow.uid).getList().size(); // We're on the app specific bubble page which displays a tri-state diff --git a/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java b/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java new file mode 100644 index 0000000000..ade9653a5f --- /dev/null +++ b/src/com/android/settings/notification/app/InvalidConversationInfoPreferenceController.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2020 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.notification.app; + +import android.app.NotificationChannel; +import android.content.Context; + +import androidx.preference.Preference; +import androidx.preference.SwitchPreference; + +import com.android.settings.R; +import com.android.settings.notification.NotificationBackend; + +public class InvalidConversationInfoPreferenceController extends NotificationPreferenceController { + + private static final String KEY = "invalid_conversation_info"; + + public InvalidConversationInfoPreferenceController(Context context, + NotificationBackend backend) { + super(context, backend); + } + + @Override + public String getPreferenceKey() { + return KEY; + } + + @Override + public boolean isAvailable() { + if (mAppRow == null) { + return false; + } + if (mAppRow.banned) { + return false; + } + return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid); + } + + @Override + public void updateState(Preference preference) { + if (mAppRow == null) { + return; + } + preference.setSummary(mContext.getString( + R.string.convo_not_supported_summary, mAppRow.label)); + } +} diff --git a/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java b/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java new file mode 100644 index 0000000000..74f5773efd --- /dev/null +++ b/src/com/android/settings/notification/app/InvalidConversationPreferenceController.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2020 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.notification.app; + +import android.app.NotificationChannel; +import android.content.Context; + +import androidx.preference.Preference; + +import com.android.settings.R; +import com.android.settings.notification.NotificationBackend; +import com.android.settingslib.RestrictedSwitchPreference; + +public class InvalidConversationPreferenceController extends NotificationPreferenceController + implements Preference.OnPreferenceChangeListener { + + private static final String KEY = "invalid_conversation_switch"; + + public InvalidConversationPreferenceController(Context context, NotificationBackend backend) { + super(context, backend); + } + + @Override + public String getPreferenceKey() { + return KEY; + } + + @Override + public boolean isAvailable() { + if (mAppRow == null) { + return false; + } + if (mAppRow.banned) { + return false; + } + return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid); + } + + @Override + public void updateState(Preference preference) { + if (mAppRow == null) { + return; + } + RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference; + pref.setDisabledByAdmin(mAdmin); + pref.setEnabled(!pref.isDisabledByAdmin()); + pref.setChecked(!mBackend.hasUserDemotedInvalidMsgApp(mAppRow.pkg, mAppRow.uid)); + preference.setSummary(mContext.getString( + R.string.conversation_section_switch_summary, mAppRow.label)); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if (mAppRow == null) { + return false; + } + mBackend.setInvalidMsgAppDemoted(mAppRow.pkg, mAppRow.uid, !((Boolean) newValue)); + return true; + } +} |