Merge "Fix NotificationAssistantPreferenceController constructor" into sc-dev am: f9bde76ab9 am: 7327a3426d

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/14829751

Change-Id: I4146ddd2a733f32aae801bcc2a2475054204276e
This commit is contained in:
Chloris Kuo
2021-06-04 20:55:40 +00:00
committed by Automerger Merge Worker
4 changed files with 30 additions and 15 deletions

View File

@@ -159,6 +159,7 @@
android:key="notification_assistant"
android:order="23"
android:title="@string/notification_assistant_title"
android:summary="@string/notification_assistant_summary"/>
android:summary="@string/notification_assistant_summary"
settings:controller="com.android.settings.notification.NotificationAssistantPreferenceController"/>
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -19,14 +19,11 @@ package com.android.settings.notification;
import android.app.Activity;
import android.app.Application;
import android.app.settings.SettingsEnums;
import android.app.usage.IUsageStatsManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
@@ -57,10 +54,11 @@ public class ConfigureNotificationSettings extends DashboardFragment implements
private static final int REQUEST_CODE = 200;
private static final String SELECTED_PREFERENCE_KEY = "selected_preference";
private static final String KEY_ADVANCED_CATEGORY = "configure_notifications_advanced";
private static final String KEY_NAS = "notification_assistant";
private RingtonePreference mRequestPreference;
private NotificationAssistantPreferenceController mNotificationAssistantPreferenceController;
@Override
public int getMetricsCategory() {
return SettingsEnums.CONFIGURE_NOTIFICATION;
@@ -88,6 +86,16 @@ public class ConfigureNotificationSettings extends DashboardFragment implements
return buildPreferenceControllers(context, app, this);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
mNotificationAssistantPreferenceController =
use(NotificationAssistantPreferenceController.class);
mNotificationAssistantPreferenceController.setFragment(this);
mNotificationAssistantPreferenceController.setBackend(new NotificationBackend());
}
@Override
protected boolean isParalleledControllers() {
return true;
@@ -105,9 +113,6 @@ public class ConfigureNotificationSettings extends DashboardFragment implements
}
});
controllers.add(new NotificationAssistantPreferenceController(context,
new NotificationBackend(), host, KEY_NAS));
controllers.add(new EmergencyBroadcastPreferenceController(context,
"app_and_notif_cell_broadcast_settings"));

View File

@@ -30,6 +30,8 @@ import com.google.common.annotations.VisibleForTesting;
public class NotificationAssistantPreferenceController extends TogglePreferenceController {
private static final String TAG = "NASPreferenceController";
private static final String KEY_NAS = "notification_assistant";
private static final int AVAILABLE = 1;
private final UserManager mUserManager;
private Fragment mFragment;
@@ -38,11 +40,8 @@ public class NotificationAssistantPreferenceController extends TogglePreferenceC
@VisibleForTesting
protected NotificationBackend mNotificationBackend;
public NotificationAssistantPreferenceController(Context context, NotificationBackend backend,
Fragment fragment, String preferenceKey) {
super(context, preferenceKey);
mNotificationBackend = backend;
mFragment = fragment;
public NotificationAssistantPreferenceController(Context context) {
super(context, KEY_NAS);
mUserManager = UserManager.get(context);
}
@@ -87,4 +86,13 @@ public class NotificationAssistantPreferenceController extends TogglePreferenceC
NotificationAssistantDialogFragment.newInstance(mFragment, cn);
dialogFragment.show(mFragment.getFragmentManager(), TAG);
}
public void setFragment(Fragment fragment) {
mFragment = fragment;
}
@VisibleForTesting
void setBackend(NotificationBackend backend) {
mNotificationBackend = backend;
}
}

View File

@@ -79,8 +79,9 @@ public class NotificationAssistantPreferenceControllerTest {
when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
when(mBackend.getDefaultNotificationAssistant()).thenReturn(mNASComponent);
mPreferenceController = new NotificationAssistantPreferenceController(mContext,
mBackend, mFragment, KEY);
mPreferenceController = new NotificationAssistantPreferenceController(mContext);
mPreferenceController.setBackend(mBackend);
mPreferenceController.setFragment(mFragment);
when(mUserManager.getProfileIds(eq(0), anyBoolean())).thenReturn(new int[] {0, 10});
when(mUserManager.getProfileIds(eq(20), anyBoolean())).thenReturn(new int[] {20});
}