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.ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY
23 import android.provider.Settings.EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_HIGHLIGHT_MENU_KEY
24 import android.provider.Settings.EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_INTENT_URI
25 import com.android.wallpaper.util.DeepLinkUtils
26 import com.android.wallpaper.util.DeepLinkUtils.EXTRA_KEY_COLLECTION_ID
27 
28 /** Utility class to check the support of multi panes integration (trampoline) */
29 class LargeScreenMultiPanesChecker : MultiPanesChecker {
30     companion object {
31         private const val TAG = "LargeScreenMultiPanesChecker"
32         private const val VALUE_HIGHLIGHT_MENU = "top_level_wallpaper"
33     }
34 
isMultiPanesEnablednull35     override fun isMultiPanesEnabled(context: Context): Boolean {
36         val pm = context.packageManager
37         val intent =
38             getMultiPanesIntent(Intent(ACTION_SET_WALLPAPER).setPackage(context.packageName))
39 
40         val resolveInfo = pm.resolveActivity(intent, MATCH_DEFAULT_ONLY)?.activityInfo
41         val displayUtils = InjectorProvider.getInjector().getDisplayUtils(context)
42         return resolveInfo != null && displayUtils.isLargeScreenDevice()
43     }
44 
getMultiPanesIntentnull45     override fun getMultiPanesIntent(intent: Intent): Intent {
46         return Intent(ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY).apply {
47             intent.extras?.let { putExtras(it) }
48             val deepLinkCollectionId = DeepLinkUtils.getCollectionId(intent)
49             deepLinkCollectionId?.let { putExtra(EXTRA_KEY_COLLECTION_ID, deepLinkCollectionId) }
50             putExtra(EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_HIGHLIGHT_MENU_KEY, VALUE_HIGHLIGHT_MENU)
51             putExtra(
52                 EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_INTENT_URI,
53                 intent.toUri(Intent.URI_INTENT_SCHEME)
54             )
55         }
56     }
57 }
58