1 /*
2  * Copyright (C) 2021 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 package com.android.wallpaper.module
17 
18 import android.content.Context
19 import android.content.Intent
20 import android.content.Intent.ACTION_SET_WALLPAPER
21 import android.content.pm.PackageManager.MATCH_DEFAULT_ONLY
22 import android.provider.Settings.*
23 
24 /**
25  * Utility class to check the support of multi panes integration (trampoline)
26  */
27 class LargeScreenMultiPanesChecker : MultiPanesChecker {
28     companion object {
29         private const val TAG = "LargeScreenMultiPanesChecker"
30         private const val VALUE_HIGHLIGHT_MENU = "top_level_wallpaper"
31     }
32 
33     override fun isMultiPanesEnabled(context: Context): Boolean {
34         val pm = context.packageManager
35         val intent = getMultiPanesIntent(
36                 Intent(ACTION_SET_WALLPAPER).setPackage(context.packageName))
37 
38         val resolveInfo = pm.resolveActivity(intent, MATCH_DEFAULT_ONLY)?.activityInfo?.enabled
39         return resolveInfo != null
40     }
41 
42     override fun getMultiPanesIntent(intent: Intent): Intent {
43         return Intent(ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY).apply {
44             putExtra(EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_HIGHLIGHT_MENU_KEY, VALUE_HIGHLIGHT_MENU)
45             putExtra(EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_INTENT_URI,
46                     intent.toUri(Intent.URI_INTENT_SCHEME))
47         };
48     }
49 }
50