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.v2 18 19 import android.content.BroadcastReceiver 20 import android.content.ComponentName 21 import android.content.Context 22 import android.content.Intent 23 import android.content.pm.PackageManager 24 import com.android.intentresolver.FeatureFlags 25 import dagger.hilt.android.AndroidEntryPoint 26 import javax.inject.Inject 27 28 @AndroidEntryPoint(BroadcastReceiver::class) 29 class ChooserSelector : Hilt_ChooserSelector() { 30 31 @Inject lateinit var featureFlags: FeatureFlags 32 onReceivenull33 override fun onReceive(context: Context, intent: Intent) { 34 super.onReceive(context, intent) 35 if (intent.action == Intent.ACTION_BOOT_COMPLETED) { 36 context.packageManager.setComponentEnabledSetting( 37 ComponentName(CHOOSER_PACKAGE, CHOOSER_PACKAGE + CHOOSER_CLASS), 38 if (featureFlags.modularFramework()) { 39 PackageManager.COMPONENT_ENABLED_STATE_ENABLED 40 } else { 41 PackageManager.COMPONENT_ENABLED_STATE_DEFAULT 42 }, 43 /* flags = */ 0, 44 ) 45 } 46 } 47 48 companion object { 49 private const val CHOOSER_PACKAGE = "com.android.intentresolver" 50 private const val CHOOSER_CLASS = ".v2.ChooserActivity" 51 } 52 } 53