1 /*
2  * Copyright (C) 2024 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.util
17 
18 import android.content.Intent
19 
20 /** Util class for deep link. */
21 object DeepLinkUtils {
22     private const val KEY_COLLECTION_ID = "collection_id"
23     private const val SCHEME = "https"
24     private const val SCHEME_SPECIFIC_PART_PREFIX = "//g.co/wallpaper"
25     const val EXTRA_KEY_COLLECTION_ID = "extra_collection_id"
26 
27     /** Checks if it is the deep link case. */
28     @JvmStatic
isDeepLinknull29     fun isDeepLink(intent: Intent): Boolean {
30         val data = intent.data
31         return data != null &&
32             SCHEME == data.scheme &&
33             data.schemeSpecificPart.startsWith(SCHEME_SPECIFIC_PART_PREFIX)
34     }
35 
36     /**
37      * Gets the wallpaper collection which wants to deep link to.
38      *
39      * @return the wallpaper collection id
40      */
41     @JvmStatic
getCollectionIdnull42     fun getCollectionId(intent: Intent): String? {
43         return if (isDeepLink(intent)) intent.data?.getQueryParameter(KEY_COLLECTION_ID)
44         else intent.getStringExtra(EXTRA_KEY_COLLECTION_ID)
45     }
46 }
47