Merge "Settings for Polite Notifications" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
54bec848cc
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.server.notification.Flags;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
/**
|
||||
* Controls the toggle that determines whether notifications
|
||||
* should only vibrate (no sound) when the device is unlocked.
|
||||
*/
|
||||
public class PoliteNotifVibrateUnlockedToggleController extends TogglePreferenceController {
|
||||
|
||||
public PoliteNotifVibrateUnlockedToggleController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
// TODO: b/291897570 - remove this when the feature flag is removed!
|
||||
if (!Flags.politeNotifications()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
return mContext.getSystemService(Vibrator.class).hasVibrator() ? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.System.getInt(mContext.getContentResolver(),
|
||||
Settings.System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED, OFF) != OFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.System.NOTIFICATION_COOLDOWN_VIBRATE_UNLOCKED, (isChecked ? ON : OFF));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return R.string.menu_key_accessibility;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.server.notification.Flags;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
/**
|
||||
* Controls the toggle that determines whether notification cooldown
|
||||
* should apply to work profiles.
|
||||
*/
|
||||
public class PoliteNotifWorkProfileToggleController extends TogglePreferenceController {
|
||||
|
||||
private final int mManagedProfileId;
|
||||
|
||||
public PoliteNotifWorkProfileToggleController(Context context, String preferenceKey) {
|
||||
this(context, preferenceKey, new AudioHelper(context));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
PoliteNotifWorkProfileToggleController(Context context, String preferenceKey,
|
||||
AudioHelper helper) {
|
||||
super(context, preferenceKey);
|
||||
mManagedProfileId = helper.getManagedProfileId(UserManager.get(mContext));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
// TODO: b/291897570 - remove this when the feature flag is removed!
|
||||
if (!Flags.politeNotifications()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
return (mManagedProfileId != UserHandle.USER_NULL) ? AVAILABLE : DISABLED_FOR_USER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, OFF, mManagedProfileId) != OFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.System.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, (isChecked ? ON : OFF),
|
||||
mManagedProfileId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return R.string.menu_key_accessibility;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.server.notification.Flags;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
|
||||
|
||||
/**
|
||||
* Controls whether polite notifications are enabled and apply to all apps or just to conversations.
|
||||
*/
|
||||
public class PoliteNotificationFilterController extends BasePreferenceController
|
||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
|
||||
static final String TAG = "PoliteNotificationFilterController";
|
||||
|
||||
private static final int POLITE_NOTIFICATIONS_ALL = 0;
|
||||
private static final int POLITE_NOTIFICATIONS_CONVERSATIONS = 1;
|
||||
private static final int POLITE_NOTIFICATIONS_DISABLED = 2;
|
||||
|
||||
public PoliteNotificationFilterController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
// TODO: b/291897570 - remove this when the feature flag is removed!
|
||||
return Flags.politeNotifications() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final ListPreference pref = (ListPreference) preference;
|
||||
|
||||
if (isPoliteNotifDisabled()) {
|
||||
pref.setValue(Integer.toString(POLITE_NOTIFICATIONS_DISABLED));
|
||||
} else if (shouldApplyForAllApps()) {
|
||||
pref.setValue(Integer.toString(POLITE_NOTIFICATIONS_ALL));
|
||||
} else {
|
||||
pref.setValue(Integer.toString(POLITE_NOTIFICATIONS_CONVERSATIONS));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
if (isPoliteNotifDisabled()) {
|
||||
return mContext.getString(R.string.notification_polite_disabled_summary);
|
||||
}
|
||||
if (shouldApplyForAllApps()) {
|
||||
return mContext.getString(R.string.notification_polite_all_apps_summary);
|
||||
} else {
|
||||
return mContext.getString(R.string.notification_polite_conversations_summary);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final int prefValue = Integer.parseInt((String) newValue);
|
||||
if (prefValue == POLITE_NOTIFICATIONS_ALL) {
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, ON);
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.System.NOTIFICATION_COOLDOWN_ALL, ON);
|
||||
} else if (prefValue == POLITE_NOTIFICATIONS_CONVERSATIONS) {
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, ON);
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.System.NOTIFICATION_COOLDOWN_ALL, OFF);
|
||||
} else if (prefValue == POLITE_NOTIFICATIONS_DISABLED) {
|
||||
Settings.System.putInt(mContext.getContentResolver(),
|
||||
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, OFF);
|
||||
} else {
|
||||
Log.e(TAG, "Unexpected preference value: " + prefValue);
|
||||
}
|
||||
refreshSummary(preference);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isPoliteNotifDisabled() {
|
||||
return Settings.System.getInt(mContext.getContentResolver(),
|
||||
Settings.System.NOTIFICATION_COOLDOWN_ENABLED, ON) == OFF;
|
||||
}
|
||||
|
||||
private boolean shouldApplyForAllApps() {
|
||||
return Settings.System.getInt(mContext.getContentResolver(),
|
||||
Settings.System.NOTIFICATION_COOLDOWN_ALL, ON) != OFF;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.server.notification.Flags;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
// TODO: b/291897570 - remove controller when the feature flag is removed!
|
||||
/**
|
||||
* Controller for polite notifications settings page.
|
||||
*/
|
||||
public class PoliteNotificationsPreferenceController extends BasePreferenceController {
|
||||
|
||||
public PoliteNotificationsPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return Flags.politeNotifications() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.app.settings.SettingsEnums;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
/**
|
||||
* Fragment for polite notifications.
|
||||
*/
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class PoliteNotificationsPreferenceFragment extends DashboardFragment {
|
||||
|
||||
private static final String POLITE_NOTIF_PREFERENCE_KEY = "polite_notifications_pref_dlg";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.SETTINGS_POLITE_NOTIFICATIONS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.polite_notifications_settings;
|
||||
}
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return "PoliteNotificationsPreferenceFragment";
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.polite_notifications_settings);
|
||||
}
|
||||
Reference in New Issue
Block a user