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 17 package com.android.intentresolver.ui 18 19 import android.content.res.Resources 20 import android.provider.DeviceConfig 21 import com.android.intentresolver.R 22 import com.android.intentresolver.inject.ApplicationOwned 23 import com.android.internal.config.sysui.SystemUiDeviceConfigFlags 24 import dagger.Module 25 import dagger.Provides 26 import dagger.hilt.InstallIn 27 import dagger.hilt.components.SingletonComponent 28 import javax.inject.Qualifier 29 import javax.inject.Singleton 30 31 @Qualifier 32 @MustBeDocumented 33 @Retention(AnnotationRetention.RUNTIME) 34 annotation class AppShortcutLimit 35 36 @Qualifier 37 @MustBeDocumented 38 @Retention(AnnotationRetention.RUNTIME) 39 annotation class EnforceShortcutLimit 40 41 @Qualifier 42 @MustBeDocumented 43 @Retention(AnnotationRetention.RUNTIME) 44 annotation class ShortcutRowLimit 45 46 @Module 47 @InstallIn(SingletonComponent::class) 48 object ShortcutPolicyModule { 49 /** 50 * Defines the limit for the number of shortcut targets provided for any single app. 51 * 52 * This value applies to both results from Shortcut-service and app-provided targets on a 53 * per-package basis. 54 */ 55 @Provides 56 @Singleton 57 @AppShortcutLimit appShortcutLimitnull58 fun appShortcutLimit(@ApplicationOwned resources: Resources): Int { 59 return resources.getInteger(R.integer.config_maxShortcutTargetsPerApp) 60 } 61 62 /** 63 * Once this value is no longer necessary it should be replaced in tests with simply replacing 64 * [AppShortcutLimit]: 65 * ``` 66 * @BindValue 67 * @AppShortcutLimit 68 * var shortcutLimit = Int.MAX_VALUE 69 * ``` 70 */ 71 @Provides 72 @Singleton 73 @EnforceShortcutLimit applyShortcutLimitnull74 fun applyShortcutLimit(): Boolean { 75 return DeviceConfig.getBoolean( 76 DeviceConfig.NAMESPACE_SYSTEMUI, 77 SystemUiDeviceConfigFlags.APPLY_SHARING_APP_LIMITS_IN_SYSUI, 78 true 79 ) 80 } 81 82 /** 83 * Defines the limit for the number of shortcuts presented within the direct share row. 84 * 85 * This value applies to all displayed direct share targets, including those from Shortcut 86 * service as well as app-provided targets. 87 */ 88 @Provides 89 @Singleton 90 @ShortcutRowLimit shortcutRowLimitnull91 fun shortcutRowLimit(@ApplicationOwned resources: Resources): Int { 92 return resources.getInteger(R.integer.config_chooser_max_targets_per_row) 93 } 94 } 95