1 /* 2 * Copyright 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 * https://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.intentresolver.interactive.domain.interactor 18 19 import android.util.Log 20 import com.android.intentresolver.IChooserController 21 import com.android.intentresolver.IChooserInteractiveSessionCallback 22 23 private const val TAG = "SessionCallback" 24 25 class SafeChooserInteractiveSessionCallback( 26 private val delegate: IChooserInteractiveSessionCallback <lambda>null27) : IChooserInteractiveSessionCallback by delegate { 28 29 override fun registerChooserController(updater: IChooserController?) { 30 if (!isAlive) return 31 runCatching { delegate.registerChooserController(updater) } 32 .onFailure { Log.e(TAG, "Failed to invoke registerChooserController", it) } 33 } 34 35 override fun onDrawerVerticalOffsetChanged(offset: Int) { 36 if (!isAlive) return 37 runCatching { delegate.onDrawerVerticalOffsetChanged(offset) } 38 .onFailure { Log.e(TAG, "Failed to invoke onDrawerVerticalOffsetChanged", it) } 39 } 40 41 private val isAlive: Boolean 42 get() = delegate.asBinder().isBinderAlive 43 } 44