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 45 private String mWallpaperLaunchExtra; 46 47 @Override addExtras(Intent intent)48 protected void addExtras(Intent intent) { 49 if (WizardManagerHelper.isAnySetupWizard(intent)) { 50 intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_ONLY); 51 52 mWallpaperLaunchExtra = 53 getResources().getString(R.string.config_wallpaper_picker_launch_extra); 54 intent.putExtra(mWallpaperLaunchExtra, LAUNCHED_SUW); 55 } else { 56 intent.putExtra(WALLPAPER_FLAVOR_EXTRA, WALLPAPER_FOCUS); 57 } 58 } 59 60 @VisibleForTesting isSuggestionComplete(Context context)61 public static boolean isSuggestionComplete(Context context) { 62 if (!isWallpaperServiceEnabled(context)) { 63 return true; 64 } 65 final WallpaperManager manager = (WallpaperManager) context.getSystemService( 66 WALLPAPER_SERVICE); 67 return manager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) > 0; 68 } 69 70 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 71 new BaseSearchIndexProvider() { 72 private static final String SUPPORT_SEARCH_INDEX_KEY = "wallpaper_type"; 73 74 @Override 75 public List<SearchIndexableRaw> getRawDataToIndex(Context context, 76 boolean enabled) { 77 final List<SearchIndexableRaw> result = new ArrayList<>(); 78 WallpaperPreferenceController controller = 79 new WallpaperPreferenceController(context, "unused key"); 80 SearchIndexableRaw data = new SearchIndexableRaw(context); 81 data.title = controller.getTitle(); 82 data.screenTitle = data.title; 83 data.intentTargetPackage = context.getPackageName(); 84 data.intentTargetClass = WallpaperSuggestionActivity.class.getName(); 85 data.intentAction = Intent.ACTION_MAIN; 86 data.key = SUPPORT_SEARCH_INDEX_KEY; 87 data.keywords = controller.getKeywords(); 88 result.add(data); 89 return result; 90 } 91 }; 92 } 93