Launch subscreens with the correct user

Test: atest
Fixes: 153556621
Change-Id: I5f3f0f408dc8e50db1762b1ce93f7748ea6332b0
This commit is contained in:
Julia Reynolds
2020-04-15 17:36:11 -04:00
parent 1845421ef8
commit e3cb4f094e
4 changed files with 24 additions and 12 deletions

View File

@@ -24,6 +24,7 @@ import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import androidx.core.text.BidiFormatter;
@@ -183,12 +184,16 @@ public class AppChannelsBypassingDndPreferenceController extends NotificationPre
channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mAppRow.pkg);
channelArgs.putString(Settings.EXTRA_CHANNEL_ID, channel.getId());
channelArgs.putBoolean(ARG_FROM_SETTINGS, true);
channelPreference.setIntent(new SubSettingLauncher(mContext)
channelPreference.setOnPreferenceClickListener(preference -> {
new SubSettingLauncher(mContext)
.setDestination(ChannelNotificationSettings.class.getName())
.setArguments(channelArgs)
.setUserHandle(UserHandle.of(mAppRow.userId))
.setTitleRes(com.android.settings.R.string.notification_channel_title)
.setSourceMetricsCategory(SettingsEnums.DND_APPS_BYPASSING)
.toIntent());
.launch();
return true;
});
mPreferenceCategory.addPreference(channelPreference);
}
mAllNotificationsToggle.setChecked(areAllChannelsBypassing());

View File

@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.ConversationChannelWrapper;
import android.text.TextUtils;
@@ -97,7 +98,10 @@ public abstract class ConversationListPreferenceController extends AbstractPrefe
conversation.getPkg(), conversation.getUid(),
conversation.getNotificationChannel().isImportantConversation()));
pref.setKey(conversation.getNotificationChannel().getId());
pref.setIntent(getIntent(conversation, pref.getTitle()));
pref.setOnPreferenceClickListener(preference -> {
getSubSettingLauncher(conversation, pref.getTitle()).launch();
return true;
});
return pref;
}
@@ -116,7 +120,8 @@ public abstract class ConversationListPreferenceController extends AbstractPrefe
: conversation.getNotificationChannel().getName();
}
Intent getIntent(ConversationChannelWrapper conversation, CharSequence title) {
SubSettingLauncher getSubSettingLauncher(ConversationChannelWrapper conversation,
CharSequence title) {
Bundle channelArgs = new Bundle();
channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, conversation.getUid());
channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, conversation.getPkg());
@@ -129,9 +134,9 @@ public abstract class ConversationListPreferenceController extends AbstractPrefe
.setDestination(ChannelNotificationSettings.class.getName())
.setArguments(channelArgs)
.setExtras(channelArgs)
.setUserHandle(UserHandle.getUserHandleForUid(conversation.getUid()))
.setTitleText(title)
.setSourceMetricsCategory(SettingsEnums.NOTIFICATION_CONVERSATION_LIST_SETTINGS)
.toIntent();
.setSourceMetricsCategory(SettingsEnums.NOTIFICATION_CONVERSATION_LIST_SETTINGS);
}
protected Comparator<ConversationChannelWrapper> mConversationComparator =

View File

@@ -20,6 +20,7 @@ import android.app.Application;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
import android.os.UserHandle;
import androidx.annotation.VisibleForTesting;
import androidx.core.text.BidiFormatter;
@@ -137,6 +138,7 @@ public class ZenModeAllBypassingAppsPreferenceController extends AbstractPrefere
new SubSettingLauncher(mContext)
.setDestination(AppChannelsBypassingDndSettings.class.getName())
.setArguments(args)
.setUserHandle(UserHandle.getUserHandleForUid(app.info.uid))
.setResultListener(mHostFragment, 0)
.setSourceMetricsCategory(
SettingsEnums.NOTIFICATION_ZEN_MODE_OVERRIDING_APP)

View File

@@ -191,7 +191,7 @@ public class ConversationListPreferenceControllerTest {
}
@Test
public void testGetIntent() {
public void testGetSubSettingLauncher() {
ConversationChannelWrapper ccw = new ConversationChannelWrapper();
NotificationChannel channel = new NotificationChannel("a", "child", 2);
channel.setConversationId("parent", "convo id");
@@ -199,7 +199,7 @@ public class ConversationListPreferenceControllerTest {
ccw.setPkg("pkg");
ccw.setUid(1);
ccw.setParentChannelLabel("parent label");
Intent intent = mController.getIntent(ccw, "title");
Intent intent = mController.getSubSettingLauncher(ccw, "title").toIntent();
Bundle extras = intent.getExtras();
assertThat(extras.getString(AppInfoBase.ARG_PACKAGE_NAME)).isEqualTo(ccw.getPkg());