Merge "Fixing notification dots settings not updated properly" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
20efbbbb1c
@@ -187,7 +187,7 @@ public class RecentsAnimationDeviceState implements
|
|||||||
SettingsCache.OnChangeListener onChangeListener =
|
SettingsCache.OnChangeListener onChangeListener =
|
||||||
enabled -> mIsOneHandedModeEnabled = enabled;
|
enabled -> mIsOneHandedModeEnabled = enabled;
|
||||||
settingsCache.register(oneHandedUri, onChangeListener);
|
settingsCache.register(oneHandedUri, onChangeListener);
|
||||||
settingsCache.dispatchOnChange(oneHandedUri);
|
mIsOneHandedModeEnabled = settingsCache.getValue(oneHandedUri);
|
||||||
runOnDestroy(() -> settingsCache.unregister(oneHandedUri, onChangeListener));
|
runOnDestroy(() -> settingsCache.unregister(oneHandedUri, onChangeListener));
|
||||||
} else {
|
} else {
|
||||||
mIsOneHandedModeEnabled = false;
|
mIsOneHandedModeEnabled = false;
|
||||||
@@ -199,7 +199,7 @@ public class RecentsAnimationDeviceState implements
|
|||||||
SettingsCache.OnChangeListener onChangeListener =
|
SettingsCache.OnChangeListener onChangeListener =
|
||||||
enabled -> mIsSwipeToNotificationEnabled = enabled;
|
enabled -> mIsSwipeToNotificationEnabled = enabled;
|
||||||
settingsCache.register(swipeBottomNotificationUri, onChangeListener);
|
settingsCache.register(swipeBottomNotificationUri, onChangeListener);
|
||||||
settingsCache.dispatchOnChange(swipeBottomNotificationUri);
|
mIsSwipeToNotificationEnabled = settingsCache.getValue(swipeBottomNotificationUri);
|
||||||
runOnDestroy(() -> settingsCache.unregister(swipeBottomNotificationUri, onChangeListener));
|
runOnDestroy(() -> settingsCache.unregister(swipeBottomNotificationUri, onChangeListener));
|
||||||
|
|
||||||
Uri setupCompleteUri = Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE);
|
Uri setupCompleteUri = Settings.Secure.getUriFor(Settings.Secure.USER_SETUP_COMPLETE);
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class SettingsChangeLogger implements
|
|||||||
SettingsCache mSettingsCache = SettingsCache.INSTANCE.get(context);
|
SettingsCache mSettingsCache = SettingsCache.INSTANCE.get(context);
|
||||||
mSettingsCache.register(NOTIFICATION_BADGING_URI,
|
mSettingsCache.register(NOTIFICATION_BADGING_URI,
|
||||||
this::onNotificationDotsChanged);
|
this::onNotificationDotsChanged);
|
||||||
mSettingsCache.dispatchOnChange(NOTIFICATION_BADGING_URI);
|
onNotificationDotsChanged(mSettingsCache.getValue(NOTIFICATION_BADGING_URI));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ArrayMap<String, LoggablePref> loadPrefKeys(Context context) {
|
private static ArrayMap<String, LoggablePref> loadPrefKeys(Context context) {
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public class LauncherAppState {
|
|||||||
mNotificationSettingsChangedListener = this::onNotificationSettingsChanged;
|
mNotificationSettingsChangedListener = this::onNotificationSettingsChanged;
|
||||||
mSettingsCache.register(NOTIFICATION_BADGING_URI,
|
mSettingsCache.register(NOTIFICATION_BADGING_URI,
|
||||||
mNotificationSettingsChangedListener);
|
mNotificationSettingsChangedListener);
|
||||||
mSettingsCache.dispatchOnChange(NOTIFICATION_BADGING_URI);
|
onNotificationSettingsChanged(mSettingsCache.getValue(NOTIFICATION_BADGING_URI));
|
||||||
}
|
}
|
||||||
|
|
||||||
public LauncherAppState(Context context, @Nullable String iconCacheFileName) {
|
public LauncherAppState(Context context, @Nullable String iconCacheFileName) {
|
||||||
|
|||||||
@@ -16,9 +16,9 @@
|
|||||||
|
|
||||||
package com.android.launcher3.notification;
|
package com.android.launcher3.notification;
|
||||||
|
|
||||||
import static com.android.launcher3.util.SettingsCache.NOTIFICATION_BADGING_URI;
|
|
||||||
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||||
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
|
||||||
|
import static com.android.launcher3.util.SettingsCache.NOTIFICATION_BADGING_URI;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
@@ -37,8 +37,8 @@ import androidx.annotation.AnyThread;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.WorkerThread;
|
import androidx.annotation.WorkerThread;
|
||||||
|
|
||||||
import com.android.launcher3.util.SettingsCache;
|
|
||||||
import com.android.launcher3.util.PackageUserKey;
|
import com.android.launcher3.util.PackageUserKey;
|
||||||
|
import com.android.launcher3.util.SettingsCache;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -213,7 +213,7 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
mNotificationSettingsChangedListener = this::onNotificationSettingsChanged;
|
mNotificationSettingsChangedListener = this::onNotificationSettingsChanged;
|
||||||
mSettingsCache.register(NOTIFICATION_BADGING_URI,
|
mSettingsCache.register(NOTIFICATION_BADGING_URI,
|
||||||
mNotificationSettingsChangedListener);
|
mNotificationSettingsChangedListener);
|
||||||
mSettingsCache.dispatchOnChange(NOTIFICATION_BADGING_URI);
|
onNotificationSettingsChanged(mSettingsCache.getValue(NOTIFICATION_BADGING_URI));
|
||||||
|
|
||||||
onNotificationFullRefresh();
|
onNotificationFullRefresh();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ package com.android.launcher3.settings;
|
|||||||
|
|
||||||
import static com.android.launcher3.settings.SettingsActivity.EXTRA_FRAGMENT_ARG_KEY;
|
import static com.android.launcher3.settings.SettingsActivity.EXTRA_FRAGMENT_ARG_KEY;
|
||||||
import static com.android.launcher3.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGS;
|
import static com.android.launcher3.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGS;
|
||||||
|
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||||
|
import static com.android.launcher3.util.SettingsCache.NOTIFICATION_BADGING_URI;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
@@ -24,6 +26,7 @@ import android.content.ComponentName;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.database.ContentObserver;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
@@ -49,6 +52,14 @@ public class NotificationDotsPreference extends Preference
|
|||||||
/** Hidden field Settings.Secure.ENABLED_NOTIFICATION_LISTENERS */
|
/** Hidden field Settings.Secure.ENABLED_NOTIFICATION_LISTENERS */
|
||||||
private static final String NOTIFICATION_ENABLED_LISTENERS = "enabled_notification_listeners";
|
private static final String NOTIFICATION_ENABLED_LISTENERS = "enabled_notification_listeners";
|
||||||
|
|
||||||
|
private final ContentObserver mListenerListObserver =
|
||||||
|
new ContentObserver(MAIN_EXECUTOR.getHandler()) {
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange) {
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public NotificationDotsPreference(
|
public NotificationDotsPreference(
|
||||||
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
@@ -66,6 +77,29 @@ public class NotificationDotsPreference extends Preference
|
|||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttached() {
|
||||||
|
super.onAttached();
|
||||||
|
SettingsCache.INSTANCE.get(getContext()).register(NOTIFICATION_BADGING_URI, this);
|
||||||
|
getContext().getContentResolver().registerContentObserver(
|
||||||
|
Settings.Secure.getUriFor(NOTIFICATION_ENABLED_LISTENERS),
|
||||||
|
false, mListenerListObserver);
|
||||||
|
updateUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateUI() {
|
||||||
|
onSettingsChanged(SettingsCache.INSTANCE.get(getContext())
|
||||||
|
.getValue(NOTIFICATION_BADGING_URI));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetached() {
|
||||||
|
super.onDetached();
|
||||||
|
SettingsCache.INSTANCE.get(getContext()).unregister(NOTIFICATION_BADGING_URI, this);
|
||||||
|
getContext().getContentResolver().unregisterContentObserver(mListenerListObserver);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void setWidgetFrameVisible(boolean isVisible) {
|
private void setWidgetFrameVisible(boolean isVisible) {
|
||||||
if (mWidgetFrameVisible != isVisible) {
|
if (mWidgetFrameVisible != isVisible) {
|
||||||
mWidgetFrameVisible = isVisible;
|
mWidgetFrameVisible = isVisible;
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ package com.android.launcher3.settings;
|
|||||||
|
|
||||||
import static androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS;
|
import static androidx.core.view.accessibility.AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS;
|
||||||
|
|
||||||
import static com.android.launcher3.util.SettingsCache.NOTIFICATION_BADGING_URI;
|
|
||||||
import static com.android.launcher3.util.SettingsCache.NOTIFICATION_ENABLED_LISTENERS;
|
|
||||||
import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY;
|
import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY;
|
||||||
import static com.android.launcher3.states.RotationHelper.getAllowRotationDefaultValue;
|
import static com.android.launcher3.states.RotationHelper.getAllowRotationDefaultValue;
|
||||||
|
|
||||||
@@ -45,7 +43,6 @@ import com.android.launcher3.R;
|
|||||||
import com.android.launcher3.Utilities;
|
import com.android.launcher3.Utilities;
|
||||||
import com.android.launcher3.config.FeatureFlags;
|
import com.android.launcher3.config.FeatureFlags;
|
||||||
import com.android.launcher3.model.WidgetsModel;
|
import com.android.launcher3.model.WidgetsModel;
|
||||||
import com.android.launcher3.util.SettingsCache;
|
|
||||||
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
|
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,11 +121,8 @@ public class SettingsActivity extends FragmentActivity
|
|||||||
*/
|
*/
|
||||||
public static class LauncherSettingsFragment extends PreferenceFragmentCompat {
|
public static class LauncherSettingsFragment extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
private SettingsCache mSettingsCache;
|
|
||||||
|
|
||||||
private String mHighLightKey;
|
private String mHighLightKey;
|
||||||
private boolean mPreferenceHighlighted = false;
|
private boolean mPreferenceHighlighted = false;
|
||||||
private NotificationDotsPreference mNotificationSettingsChangedListener;
|
|
||||||
private Preference mDeveloperOptionPref;
|
private Preference mDeveloperOptionPref;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -172,22 +166,7 @@ public class SettingsActivity extends FragmentActivity
|
|||||||
protected boolean initPreference(Preference preference) {
|
protected boolean initPreference(Preference preference) {
|
||||||
switch (preference.getKey()) {
|
switch (preference.getKey()) {
|
||||||
case NOTIFICATION_DOTS_PREFERENCE_KEY:
|
case NOTIFICATION_DOTS_PREFERENCE_KEY:
|
||||||
if (WidgetsModel.GO_DISABLE_NOTIFICATION_DOTS) {
|
return !WidgetsModel.GO_DISABLE_NOTIFICATION_DOTS;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listen to system notification dot settings while this UI is active.
|
|
||||||
mSettingsCache = SettingsCache.INSTANCE.get(getActivity());
|
|
||||||
mNotificationSettingsChangedListener =
|
|
||||||
((NotificationDotsPreference) preference);
|
|
||||||
mSettingsCache.register(NOTIFICATION_BADGING_URI,
|
|
||||||
(NotificationDotsPreference) mNotificationSettingsChangedListener);
|
|
||||||
// Also listen if notification permission changes
|
|
||||||
mSettingsCache.register(NOTIFICATION_ENABLED_LISTENERS,
|
|
||||||
mNotificationSettingsChangedListener);
|
|
||||||
mSettingsCache.dispatchOnChange(NOTIFICATION_BADGING_URI);
|
|
||||||
mSettingsCache.dispatchOnChange(NOTIFICATION_ENABLED_LISTENERS);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case ALLOW_ROTATION_PREFERENCE_KEY:
|
case ALLOW_ROTATION_PREFERENCE_KEY:
|
||||||
if (getResources().getBoolean(R.bool.allow_rotation)) {
|
if (getResources().getBoolean(R.bool.allow_rotation)) {
|
||||||
@@ -269,16 +248,5 @@ public class SettingsActivity extends FragmentActivity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
if (mSettingsCache != null) {
|
|
||||||
mSettingsCache.unregister(NOTIFICATION_BADGING_URI,
|
|
||||||
mNotificationSettingsChangedListener);
|
|
||||||
mSettingsCache.unregister(NOTIFICATION_ENABLED_LISTENERS,
|
|
||||||
mNotificationSettingsChangedListener);
|
|
||||||
}
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,12 +39,11 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
* {@link #unregister(Uri, OnChangeListener)} methods.
|
* {@link #unregister(Uri, OnChangeListener)} methods.
|
||||||
*
|
*
|
||||||
* This can be used as a normal cache without any listeners as well via the
|
* This can be used as a normal cache without any listeners as well via the
|
||||||
* {@link #getValue(Uri, int)} and {@link #dispatchOnChange(Uri)} to update (and subsequently call
|
* {@link #getValue(Uri, int)} and {@link #onChange)} to update (and subsequently call
|
||||||
* get)
|
* get)
|
||||||
*
|
*
|
||||||
* The cache will be invalidated/updated through the normal
|
* The cache will be invalidated/updated through the normal
|
||||||
* {@link ContentObserver#onChange(boolean)} calls
|
* {@link ContentObserver#onChange(boolean)} calls
|
||||||
* or can be force updated by calling {@link #dispatchOnChange(Uri)}.
|
|
||||||
*
|
*
|
||||||
* Cache will also be updated if a key queried is missing (even if it has no listeners registered).
|
* Cache will also be updated if a key queried is missing (even if it has no listeners registered).
|
||||||
*/
|
*/
|
||||||
@@ -58,9 +57,6 @@ public class SettingsCache extends ContentObserver {
|
|||||||
/** Hidden field Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED */
|
/** Hidden field Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED */
|
||||||
public static final String ONE_HANDED_SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED =
|
public static final String ONE_HANDED_SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED =
|
||||||
"swipe_bottom_to_notification_enabled";
|
"swipe_bottom_to_notification_enabled";
|
||||||
/** Hidden field Settings.Secure.ENABLED_NOTIFICATION_LISTENERS */
|
|
||||||
public static final Uri NOTIFICATION_ENABLED_LISTENERS =
|
|
||||||
Settings.Secure.getUriFor("enabled_notification_listeners");
|
|
||||||
public static final Uri ROTATION_SETTING_URI =
|
public static final Uri ROTATION_SETTING_URI =
|
||||||
Settings.System.getUriFor(ACCELEROMETER_ROTATION);
|
Settings.System.getUriFor(ACCELEROMETER_ROTATION);
|
||||||
|
|
||||||
@@ -99,6 +95,14 @@ public class SettingsCache extends ContentObserver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value for this classes key from the cache. If not in cache, will call
|
||||||
|
* {@link #updateValue(Uri, int)} to fetch.
|
||||||
|
*/
|
||||||
|
public boolean getValue(Uri keySetting) {
|
||||||
|
return getValue(keySetting, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value for this classes key from the cache. If not in cache, will call
|
* Returns the value for this classes key from the cache. If not in cache, will call
|
||||||
* {@link #updateValue(Uri, int)} to fetch.
|
* {@link #updateValue(Uri, int)} to fetch.
|
||||||
@@ -139,14 +143,6 @@ public class SettingsCache extends ContentObserver {
|
|||||||
return newVal;
|
return newVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Force update a change for a given URI and have all listeners for that URI receive callbacks
|
|
||||||
* even if the value is unchanged.
|
|
||||||
*/
|
|
||||||
public void dispatchOnChange(Uri uri) {
|
|
||||||
onChange(true, uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call to stop receiving updates on the given {@param listener}.
|
* Call to stop receiving updates on the given {@param listener}.
|
||||||
* This Uri/Listener pair must correspond to the same pair called with for
|
* This Uri/Listener pair must correspond to the same pair called with for
|
||||||
|
|||||||
Reference in New Issue
Block a user