• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Activity;
20 import android.app.WallpaperManager;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.content.pm.PackageManager;
24 import android.os.Bundle;
25 import android.support.annotation.VisibleForTesting;
26 
27 import com.android.internal.logging.nano.MetricsProto;
28 import com.android.settings.R;
29 import com.android.settings.core.SubSettingLauncher;
30 
31 public class WallpaperSuggestionActivity extends Activity {
32 
33     @Override
onCreate(Bundle savedInstanceState)34     protected void onCreate(Bundle savedInstanceState) {
35         super.onCreate(savedInstanceState);
36         final PackageManager pm = getPackageManager();
37         final Intent intent = new Intent()
38                 .setClassName(getString(R.string.config_wallpaper_picker_package),
39                         getString(R.string.config_wallpaper_picker_class))
40                 .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
41         if (pm.resolveActivity(intent, 0) != null) {
42             startActivity(intent);
43         } else {
44             startFallbackSuggestion();
45         }
46 
47         finish();
48     }
49 
50     @VisibleForTesting
startFallbackSuggestion()51     void startFallbackSuggestion() {
52         // fall back to default wallpaper picker
53         new SubSettingLauncher(this)
54                 .setDestination(WallpaperTypeSettings.class.getName())
55                 .setTitle(R.string.wallpaper_suggestion_title)
56                 .setSourceMetricsCategory(MetricsProto.MetricsEvent.DASHBOARD_SUMMARY)
57                 .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT)
58                 .launch();
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 
isWallpaperServiceEnabled(Context context)71     private static boolean isWallpaperServiceEnabled(Context context) {
72         return context.getResources().getBoolean(
73                 com.android.internal.R.bool.config_enableWallpaperService);
74     }
75 }
76