1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.wallpaper; 18 19 import android.app.WallpaperManager; 20 import android.content.Context; 21 import android.content.Intent; 22 23 import androidx.annotation.VisibleForTesting; 24 25 import com.android.settings.R; 26 import com.android.settings.display.WallpaperPreferenceController; 27 import com.android.settings.search.BaseSearchIndexProvider; 28 import com.android.settingslib.search.Indexable; 29 import com.android.settingslib.search.SearchIndexable; 30 import com.android.settingslib.search.SearchIndexableRaw; 31 32 import com.google.android.setupcompat.util.WizardManagerHelper; 33 34 import java.util.ArrayList; 35 import java.util.List; 36 37 @SearchIndexable 38 public class WallpaperSuggestionActivity extends StyleSuggestionActivityBase implements Indexable { 39 40 private static final String WALLPAPER_FLAVOR_EXTRA = "com.android.launcher3.WALLPAPER_FLAVOR"; 41 private static final String WALLPAPER_FOCUS = "focus_wallpaper"; 42 private static final String WALLPAPER_ONLY = "wallpaper_only"; 43 private static final String LAUNCHED_SUW = "app_launched_suw"; 44 private static final String LAUNCH_SOURCE_SETTINGS_SEARCH = "app_launched_settings_search"; 45 46 @Override addExtras(Intent intent)47 protected void addExtras(Intent intent) { 48 String wallpaperLaunchExtra = 49 getResources().getString(R.string.config_wallpaper_picker_launch_extra);; 50 if (WizardManagerHelper.isAnySetupWizard(intent)) { 51 intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_ONLY); 52 intent.putExtra(wallpaperLaunchExtra, LAUNCHED_SUW); 53 } else { 54 // This is the case when user enter the wallpaper picker from the search result entry 55 // on the Settings app 56 intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_FOCUS); 57 intent.putExtra(wallpaperLaunchExtra, LAUNCH_SOURCE_SETTINGS_SEARCH); 58 } 59 } 60 61 @VisibleForTesting isSuggestionComplete(Context context)62 public static boolean isSuggestionComplete(Context context) { 63 if (!isWallpaperServiceEnabled(context)) { 64 return true; 65 } 66 final WallpaperManager manager = (WallpaperManager) context.getSystemService( 67 WALLPAPER_SERVICE); 68 return manager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) > 0; 69 } 70 71 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 72 new BaseSearchIndexProvider() { 73 private static final String SUPPORT_SEARCH_INDEX_KEY = "wallpaper_type"; 74 75 @Override 76 public List<SearchIndexableRaw> getRawDataToIndex(Context context, 77 boolean enabled) { 78 final List<SearchIndexableRaw> result = new ArrayList<>(); 79 WallpaperPreferenceController controller = 80 new WallpaperPreferenceController(context, "unused key"); 81 SearchIndexableRaw data = new SearchIndexableRaw(context); 82 data.title = controller.getTitle(); 83 data.screenTitle = data.title; 84 data.intentTargetPackage = context.getPackageName(); 85 data.intentTargetClass = WallpaperSuggestionActivity.class.getName(); 86 data.intentAction = Intent.ACTION_MAIN; 87 data.key = SUPPORT_SEARCH_INDEX_KEY; 88 data.keywords = controller.getKeywords(); 89 result.add(data); 90 return result; 91 } 92 }; 93 } 94