1 /* 2 * Copyright (C) 2020 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 import android.net.Uri; 20 21 /** Util class for deep link. */ 22 public class DeepLinkUtils { 23 private static final String KEY_COLLECTION_ID = "collection_id"; 24 private static final String SCHEME = "https"; 25 private static final String SCHEME_SPECIFIC_PART_PREFIX = "//g.co/wallpaper"; 26 27 /** 28 * Checks if it is the deep link case. 29 */ isDeepLink(Intent intent)30 public static boolean isDeepLink(Intent intent) { 31 Uri data = intent.getData(); 32 return data != null && SCHEME.equals(data.getScheme()) 33 && data.getSchemeSpecificPart().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 */ getCollectionId(Intent intent)41 public static String getCollectionId(Intent intent) { 42 return isDeepLink(intent) ? intent.getData().getQueryParameter(KEY_COLLECTION_ID) : null; 43 } 44 } 45