1 /* <lambda>null2 * 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 17 package com.android.launcher3.util 18 19 import android.os.IBinder 20 import com.android.launcher3.model.data.ItemInfo 21 import com.android.launcher3.model.data.ItemInfo.NO_ID 22 23 /** Info parameters that can be used to identify a Launcher object */ 24 data class StableViewInfo(val itemId: Int, val containerId: Int, val stableId: Any) { 25 26 fun matches(info: ItemInfo?) = 27 info != null && 28 itemId == info.id && 29 containerId == info.container && 30 stableId == info.stableId 31 32 companion object { 33 34 private fun ItemInfo.toStableViewInfo() = 35 stableId?.let { sId -> 36 if (id != NO_ID || container != NO_ID) StableViewInfo(id, container, sId) else null 37 } 38 39 /** 40 * Return a new launch cookie for the activity launch if supported. 41 * 42 * @param info the item info for the launch 43 */ 44 @JvmStatic 45 fun toLaunchCookie(info: ItemInfo?) = 46 info?.toStableViewInfo()?.let { ObjectWrapper.wrap(it) } 47 48 /** 49 * Unwraps the binder and returns the first non-null StableViewInfo in the list or null if 50 * none can be found 51 */ 52 @JvmStatic 53 fun fromLaunchCookies(launchCookies: List<IBinder>) = 54 launchCookies.firstNotNullOfOrNull { ObjectWrapper.unwrap<StableViewInfo>(it) } 55 } 56 } 57