diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 9dd4732072f..20742885742 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -848,6 +848,23 @@ + + + + + + + + + + + + + + + diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java index bfa44e5216e..35905546a03 100644 --- a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java +++ b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java @@ -31,6 +31,7 @@ import com.android.settings.notification.ZenOnboardingActivity; import com.android.settings.notification.ZenSuggestionActivity; import com.android.settings.overlay.FeatureFactory; import com.android.settings.password.ScreenLockSuggestionActivity; +import com.android.settings.wallpaper.StyleSuggestionActivity; import com.android.settings.wallpaper.WallpaperSuggestionActivity; import com.android.settings.wifi.calling.WifiCallingSuggestionActivity; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; @@ -62,6 +63,8 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider final String className = component.getClassName(); if (className.equals(WallpaperSuggestionActivity.class.getName())) { return WallpaperSuggestionActivity.isSuggestionComplete(context); + } else if (className.equals(StyleSuggestionActivity.class.getName())) { + return StyleSuggestionActivity.isSuggestionComplete(context); } else if (className.equals(FingerprintSuggestionActivity.class.getName())) { return FingerprintSuggestionActivity.isSuggestionComplete(context); } else if (className.equals(FingerprintEnrollSuggestionActivity.class.getName())) { diff --git a/src/com/android/settings/wallpaper/StyleSuggestionActivity.java b/src/com/android/settings/wallpaper/StyleSuggestionActivity.java new file mode 100644 index 00000000000..376724b0cae --- /dev/null +++ b/src/com/android/settings/wallpaper/StyleSuggestionActivity.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2019 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.wallpaper; + +import android.content.Context; +import android.provider.Settings; +import android.text.TextUtils; + +import com.android.internal.annotations.VisibleForTesting; + +public class StyleSuggestionActivity extends StyleSuggestionActivityBase { + + @VisibleForTesting + public static boolean isSuggestionComplete(Context context) { + if (!isWallpaperServiceEnabled(context)) { + return true; + } + + final String currentTheme = Settings.Secure.getStringForUser(context.getContentResolver(), + Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES, context.getUserId()); + if (TextUtils.isEmpty(currentTheme)) { + // Empty value means the user has not visited the styles tab yet + return false; + } + return true; + } +} diff --git a/src/com/android/settings/wallpaper/StyleSuggestionActivityBase.java b/src/com/android/settings/wallpaper/StyleSuggestionActivityBase.java new file mode 100644 index 00000000000..abbf3dc8146 --- /dev/null +++ b/src/com/android/settings/wallpaper/StyleSuggestionActivityBase.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2019 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.wallpaper; + +import android.app.Activity; +import android.app.settings.SettingsEnums; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.Bundle; + +import androidx.annotation.VisibleForTesting; + +import com.android.settings.R; +import com.android.settings.core.SubSettingLauncher; +import com.android.settings.display.WallpaperPreferenceController; + +import com.google.android.setupcompat.util.WizardManagerHelper; + +public abstract class StyleSuggestionActivityBase extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + final PackageManager pm = getPackageManager(); + final Intent intent = new Intent() + .setComponent(new WallpaperPreferenceController(this, "dummy key") + .getComponentName()) + .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); + + // passing the necessary extra to next page + WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent); + + addExtras(intent); + + if (pm.resolveActivity(intent, 0) != null) { + startActivity(intent); + } else { + startFallbackSuggestion(); + } + + finish(); + } + + /** + * Add any extras to the intent before launching the wallpaper activity + * @param intent + */ + protected void addExtras(Intent intent) { } + + @VisibleForTesting + void startFallbackSuggestion() { + // fall back to default wallpaper picker + new SubSettingLauncher(this) + .setDestination(WallpaperTypeSettings.class.getName()) + .setTitleRes(R.string.wallpaper_suggestion_title) + .setSourceMetricsCategory(SettingsEnums.DASHBOARD_SUMMARY) + .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT) + .launch(); + } + + protected static boolean isWallpaperServiceEnabled(Context context) { + return context.getResources().getBoolean( + com.android.internal.R.bool.config_enableWallpaperService); + } +} diff --git a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java index fe23d742770..57222f1a41d 100644 --- a/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java +++ b/src/com/android/settings/wallpaper/WallpaperSuggestionActivity.java @@ -16,63 +16,31 @@ package com.android.settings.wallpaper; -import android.app.Activity; import android.app.WallpaperManager; -import android.app.settings.SettingsEnums; import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.content.pm.PackageManager; -import android.os.Bundle; import androidx.annotation.VisibleForTesting; -import com.android.settings.R; -import com.android.settings.core.SubSettingLauncher; import com.android.settings.display.WallpaperPreferenceController; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import com.android.settings.search.SearchIndexableRaw; import com.android.settingslib.search.SearchIndexable; -import com.google.android.setupcompat.util.WizardManagerHelper; - import java.util.ArrayList; import java.util.List; @SearchIndexable -public class WallpaperSuggestionActivity extends Activity implements Indexable { +public class WallpaperSuggestionActivity extends StyleSuggestionActivityBase implements Indexable { + + private static final String WALLPAPER_FLAVOR_EXTRA = "com.android.launcher3.WALLPAPER_FLAVOR"; + private static final String WALLPAPER_FOCUS = "focus_wallpaper"; @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - final PackageManager pm = getPackageManager(); - final Intent intent = new Intent() - .setComponent(new WallpaperPreferenceController(this, "dummy key") - .getComponentName()) - .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); - - // passing the necessary extra to next page - WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent); - - if (pm.resolveActivity(intent, 0) != null) { - startActivity(intent); - } else { - startFallbackSuggestion(); - } - - finish(); - } - - @VisibleForTesting - void startFallbackSuggestion() { - // fall back to default wallpaper picker - new SubSettingLauncher(this) - .setDestination(WallpaperTypeSettings.class.getName()) - .setTitleRes(R.string.wallpaper_suggestion_title) - .setSourceMetricsCategory(SettingsEnums.DASHBOARD_SUMMARY) - .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT) - .launch(); + protected void addExtras(Intent intent) { + intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_FOCUS); } @VisibleForTesting @@ -85,11 +53,6 @@ public class WallpaperSuggestionActivity extends Activity implements Indexable { return manager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) > 0; } - private static boolean isWallpaperServiceEnabled(Context context) { - return context.getResources().getBoolean( - com.android.internal.R.bool.config_enableWallpaperService); - } - public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider() { private static final String SUPPORT_SEARCH_INDEX_KEY = "wallpaper_type"; diff --git a/tests/robotests/src/com/android/settings/wallpaper/StyleSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/wallpaper/StyleSuggestionActivityTest.java new file mode 100644 index 00000000000..120c780ab9d --- /dev/null +++ b/tests/robotests/src/com/android/settings/wallpaper/StyleSuggestionActivityTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2019 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.wallpaper; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.when; + +import android.content.ContentResolver; +import android.content.Context; +import android.content.res.Resources; +import android.provider.Settings; + +import com.android.settings.testutils.shadow.ShadowSecureSettings; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +@RunWith(RobolectricTestRunner.class) +public class StyleSuggestionActivityTest { + + @Mock + private Context mContext; + @Mock + private Resources mResources; + @Mock + private ContentResolver mContentResolver; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + when(mContext.getResources()).thenReturn(mResources); + when(mContext.getContentResolver()).thenReturn(mContentResolver); + } + + @Test + public void wallpaperServiceEnabled_no_shouldReturnTrue() { + when(mResources.getBoolean(com.android.internal.R.bool.config_enableWallpaperService)) + .thenReturn(false); + assertThat(StyleSuggestionActivity.isSuggestionComplete(mContext)).isTrue(); + } + + @Test + @Config(shadows = ShadowSecureSettings.class) + public void hasStyleSet_yes_shouldReturnTrue() { + when(mResources.getBoolean(com.android.internal.R.bool.config_enableWallpaperService)) + .thenReturn(true); + + Settings.Secure.putString(mContentResolver, + Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES, "test"); + assertThat(StyleSuggestionActivity.isSuggestionComplete(mContext)).isTrue(); + } + + @Test + @Config(shadows = ShadowSecureSettings.class) + public void hasStyleSet_no_shouldReturnFalse() { + when(mResources.getBoolean(com.android.internal.R.bool.config_enableWallpaperService)) + .thenReturn(true); + + Settings.Secure.putString(mContentResolver, + Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES, null); + assertThat(StyleSuggestionActivity.isSuggestionComplete(mContext)).isFalse(); + } +}