From 132e7341ea10b23a78b0f69f15471d1bef6802bb Mon Sep 17 00:00:00 2001 From: paulzhchen Date: Fri, 12 Apr 2024 13:49:52 +0000 Subject: [PATCH] Add FeatureProvider for SyncAcrossDevices Settings integration. Bug: 330498032 Test: FakeFeatureFactory Change-Id: Iccf7ca4411a03d29e9eeba6c1544ccbd95b97654 --- .../SyncAcrossDevicesFeatureCallback.java | 38 +++++++++++++++++++ .../SyncAcrossDevicesFeatureProvider.java | 32 ++++++++++++++++ .../SyncAcrossDevicesFeatureProviderImpl.java | 34 +++++++++++++++++ .../SyncAcrossDevicesFeatureUpdater.java | 34 +++++++++++++++++ .../settings/overlay/FeatureFactory.kt | 6 +++ .../settings/overlay/FeatureFactoryImpl.kt | 6 +++ .../testutils/FakeFeatureFactory.java | 10 ++++- .../settings/testutils/FakeFeatureFactory.kt | 3 ++ .../testutils/FakeFeatureFactory.java | 8 ++++ 9 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureCallback.java create mode 100644 src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureProvider.java create mode 100644 src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureProviderImpl.java create mode 100644 src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureUpdater.java diff --git a/src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureCallback.java b/src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureCallback.java new file mode 100644 index 00000000000..6dfe183a4b3 --- /dev/null +++ b/src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureCallback.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2024 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.syncacrossdevices; + +import androidx.annotation.Nullable; +import androidx.preference.Preference; + +/** Callback to add or remove {@link Preference} in Sync Across Devices feature. */ +public interface SyncAcrossDevicesFeatureCallback { + + /** + * Called when a sync across devices feature is added + * + * @param preference present the feature + */ + void onFeatureAdded(@Nullable Preference preference); + + /** + * Called when a sync across devices feature is removed + * + * @param preference present the feature + */ + void onFeatureRemoved(@Nullable Preference preference); +} diff --git a/src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureProvider.java b/src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureProvider.java new file mode 100644 index 00000000000..d575d591922 --- /dev/null +++ b/src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureProvider.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2024 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.syncacrossdevices; + +import android.content.Context; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +/** Feature provider for the Sync Across Devices. */ +public interface SyncAcrossDevicesFeatureProvider { + + /** Returns the SyncAcrossDevicesFeatureUpdater of the Sync Across Devices feature */ + @Nullable + SyncAcrossDevicesFeatureUpdater getSyncAcrossDevicesFeatureUpdater( + @NonNull Context context, + @NonNull SyncAcrossDevicesFeatureCallback featurePreferenceCallback); +} diff --git a/src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureProviderImpl.java b/src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureProviderImpl.java new file mode 100644 index 00000000000..090bf637806 --- /dev/null +++ b/src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureProviderImpl.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024 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.syncacrossdevices; + +import android.content.Context; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +/** Default implementation for {@link SyncAcrossDevicesFeatureProvider} */ +public class SyncAcrossDevicesFeatureProviderImpl implements SyncAcrossDevicesFeatureProvider { + + @Override + @Nullable + public SyncAcrossDevicesFeatureUpdater getSyncAcrossDevicesFeatureUpdater( + @NonNull Context context, + @NonNull SyncAcrossDevicesFeatureCallback featurePreferenceCallback) { + return new SyncAcrossDevicesFeatureUpdater() {}; + } +} diff --git a/src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureUpdater.java b/src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureUpdater.java new file mode 100644 index 00000000000..f9407b0d545 --- /dev/null +++ b/src/com/android/settings/notification/syncacrossdevices/SyncAcrossDevicesFeatureUpdater.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024 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.syncacrossdevices; + +import android.content.Context; + +import androidx.annotation.Nullable; + +/** + * Updates the sync across devices feature state. It notifies the upper level whether to add/remove + * the preference through {@link SyncAcrossDevicesFeatureCallback} + */ +public interface SyncAcrossDevicesFeatureUpdater { + + /** Forces to update the list of the Sync Across Devices feature. */ + default void forceUpdate() {} + + /** Sets the context to generate the {@link Preference}, so it could get the correct theme. */ + default void setPreferenceContext(@Nullable Context preferenceContext) {} +} diff --git a/src/com/android/settings/overlay/FeatureFactory.kt b/src/com/android/settings/overlay/FeatureFactory.kt index 53ad8ba642e..ef63f194ca2 100644 --- a/src/com/android/settings/overlay/FeatureFactory.kt +++ b/src/com/android/settings/overlay/FeatureFactory.kt @@ -38,6 +38,7 @@ import com.android.settings.fuelgauge.PowerUsageFeatureProvider import com.android.settings.homepage.contextualcards.ContextualCardFeatureProvider import com.android.settings.inputmethod.KeyboardSettingsFeatureProvider import com.android.settings.localepicker.LocaleFeatureProvider +import com.android.settings.notification.syncacrossdevices.SyncAcrossDevicesFeatureProvider import com.android.settings.onboarding.OnboardingFeatureProvider import com.android.settings.overlay.FeatureFactory.Companion.setFactory import com.android.settings.panel.PanelFeatureProvider @@ -188,6 +189,11 @@ abstract class FeatureFactory { */ abstract val audioSharingFeatureProvider: AudioSharingFeatureProvider + /** + * Gets implementation for sync across devices related feature. + */ + abstract val syncAcrossDevicesFeatureProvider: SyncAcrossDevicesFeatureProvider + companion object { private var _factory: FeatureFactory? = null diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.kt b/src/com/android/settings/overlay/FeatureFactoryImpl.kt index 1770209cc86..c74260c4070 100644 --- a/src/com/android/settings/overlay/FeatureFactoryImpl.kt +++ b/src/com/android/settings/overlay/FeatureFactoryImpl.kt @@ -55,6 +55,8 @@ import com.android.settings.homepage.contextualcards.ContextualCardFeatureProvid import com.android.settings.inputmethod.KeyboardSettingsFeatureProvider import com.android.settings.inputmethod.KeyboardSettingsFeatureProviderImpl import com.android.settings.localepicker.LocaleFeatureProviderImpl +import com.android.settings.notification.syncacrossdevices.SyncAcrossDevicesFeatureProvider +import com.android.settings.notification.syncacrossdevices.SyncAcrossDevicesFeatureProviderImpl import com.android.settings.panel.PanelFeatureProviderImpl import com.android.settings.search.SearchFeatureProvider import com.android.settings.search.SearchFeatureProviderImpl @@ -197,4 +199,8 @@ open class FeatureFactoryImpl : FeatureFactory() { override val audioSharingFeatureProvider: AudioSharingFeatureProvider by lazy { AudioSharingFeatureProviderImpl() } + + override val syncAcrossDevicesFeatureProvider: SyncAcrossDevicesFeatureProvider by lazy { + SyncAcrossDevicesFeatureProviderImpl() + } } diff --git a/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java b/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java index 38683d01ea6..71f8e5834fe 100644 --- a/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java +++ b/tests/robotests/testutils/com/android/settings/testutils/FakeFeatureFactory.java @@ -40,6 +40,7 @@ import com.android.settings.fuelgauge.PowerUsageFeatureProvider; import com.android.settings.homepage.contextualcards.ContextualCardFeatureProvider; import com.android.settings.inputmethod.KeyboardSettingsFeatureProvider; import com.android.settings.localepicker.LocaleFeatureProvider; +import com.android.settings.notification.syncacrossdevices.SyncAcrossDevicesFeatureProvider; import com.android.settings.onboarding.OnboardingFeatureProvider; import com.android.settings.overlay.DockUpdaterFeatureProvider; import com.android.settings.overlay.FeatureFactory; @@ -103,6 +104,7 @@ public class FakeFeatureFactory extends FeatureFactory { public PrivateSpaceLoginFeatureProvider mPrivateSpaceLoginFeatureProvider; public DisplayFeatureProvider mDisplayFeatureProvider; public AudioSharingFeatureProvider mAudioSharingFeatureProvider; + public SyncAcrossDevicesFeatureProvider mSyncAcrossDevicesFeatureProvider; /** * Call this in {@code @Before} method of the test class to use fake factory. @@ -150,9 +152,10 @@ public class FakeFeatureFactory extends FeatureFactory { mStylusFeatureProvider = mock(StylusFeatureProvider.class); mOnboardingFeatureProvider = mock(OnboardingFeatureProvider.class); mFastPairFeatureProvider = mock(FastPairFeatureProvider.class); - mPrivateSpaceLoginFeatureProvider = mock(PrivateSpaceLoginFeatureProvider.class); + mPrivateSpaceLoginFeatureProvider = mock(PrivateSpaceLoginFeatureProvider.class); mDisplayFeatureProvider = mock(DisplayFeatureProvider.class); mAudioSharingFeatureProvider = mock(AudioSharingFeatureProvider.class); + mSyncAcrossDevicesFeatureProvider = mock(SyncAcrossDevicesFeatureProvider.class); } @Override @@ -340,5 +343,10 @@ public class FakeFeatureFactory extends FeatureFactory { public AudioSharingFeatureProvider getAudioSharingFeatureProvider() { return mAudioSharingFeatureProvider; } + + @Override + public SyncAcrossDevicesFeatureProvider getSyncAcrossDevicesFeatureProvider() { + return mSyncAcrossDevicesFeatureProvider; + } } diff --git a/tests/spa_unit/src/com/android/settings/testutils/FakeFeatureFactory.kt b/tests/spa_unit/src/com/android/settings/testutils/FakeFeatureFactory.kt index 606db8e1c87..e1dcda211a3 100644 --- a/tests/spa_unit/src/com/android/settings/testutils/FakeFeatureFactory.kt +++ b/tests/spa_unit/src/com/android/settings/testutils/FakeFeatureFactory.kt @@ -39,6 +39,7 @@ import com.android.settings.fuelgauge.PowerUsageFeatureProvider import com.android.settings.homepage.contextualcards.ContextualCardFeatureProvider import com.android.settings.inputmethod.KeyboardSettingsFeatureProvider import com.android.settings.localepicker.LocaleFeatureProvider +import com.android.settings.notification.syncacrossdevices.SyncAcrossDevicesFeatureProvider import com.android.settings.overlay.DockUpdaterFeatureProvider import com.android.settings.overlay.FeatureFactory import com.android.settings.overlay.SurveyFeatureProvider @@ -152,4 +153,6 @@ class FakeFeatureFactory : FeatureFactory() { get() = TODO("Not yet implemented") override val audioSharingFeatureProvider: AudioSharingFeatureProvider get() = TODO("Not yet implemented") + override val syncAcrossDevicesFeatureProvider: SyncAcrossDevicesFeatureProvider + get() = TODO("Not yet implemented") } diff --git a/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java index 29758de5555..cc129fd23a8 100644 --- a/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java +++ b/tests/unit/src/com/android/settings/testutils/FakeFeatureFactory.java @@ -40,6 +40,7 @@ import com.android.settings.fuelgauge.PowerUsageFeatureProvider; import com.android.settings.homepage.contextualcards.ContextualCardFeatureProvider; import com.android.settings.inputmethod.KeyboardSettingsFeatureProvider; import com.android.settings.localepicker.LocaleFeatureProvider; +import com.android.settings.notification.syncacrossdevices.SyncAcrossDevicesFeatureProvider; import com.android.settings.onboarding.OnboardingFeatureProvider; import com.android.settings.overlay.DockUpdaterFeatureProvider; import com.android.settings.overlay.FeatureFactory; @@ -102,6 +103,7 @@ public class FakeFeatureFactory extends FeatureFactory { public PrivateSpaceLoginFeatureProvider mPrivateSpaceLoginFeatureProvider; public DisplayFeatureProvider mDisplayFeatureProvider; public AudioSharingFeatureProvider mAudioSharingFeatureProvider; + public SyncAcrossDevicesFeatureProvider mSyncAcrossDevicesFeatureProvider; /** Call this in {@code @Before} method of the test class to use fake factory. */ public static FakeFeatureFactory setupForTest() { @@ -154,6 +156,7 @@ public class FakeFeatureFactory extends FeatureFactory { mPrivateSpaceLoginFeatureProvider = mock(PrivateSpaceLoginFeatureProvider.class); mDisplayFeatureProvider = mock(DisplayFeatureProvider.class); mAudioSharingFeatureProvider = mock(AudioSharingFeatureProvider.class); + mSyncAcrossDevicesFeatureProvider = mock(SyncAcrossDevicesFeatureProvider.class); } @Override @@ -341,4 +344,9 @@ public class FakeFeatureFactory extends FeatureFactory { public AudioSharingFeatureProvider getAudioSharingFeatureProvider() { return mAudioSharingFeatureProvider; } + + @Override + public SyncAcrossDevicesFeatureProvider getSyncAcrossDevicesFeatureProvider() { + return mSyncAcrossDevicesFeatureProvider; + } }