Merge changes from topic "jr-update" into rvc-dev
* changes: Update conversation launch point Add settings for apps that don't use full conversations
This commit is contained in:
committed by
Android (Google) Code Review
commit
4bbe564aea
@@ -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;
|
||||
}
|
||||
}
|
@@ -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
|
||||
*/
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user