1 /* 2 * Copyright (C) 2022 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.settings.spa 18 19 import android.app.Activity 20 import android.content.Intent 21 import android.os.Bundle 22 import com.android.settings.activityembedding.ActivityEmbeddingUtils 23 import com.android.settings.activityembedding.EmbeddedDeepLinkUtils.tryStartMultiPaneDeepLink 24 import com.android.settings.spa.SpaDestination.Companion.getDestination 25 import com.android.settingslib.spa.framework.util.SESSION_EXTERNAL 26 import com.android.settingslib.spa.framework.util.appendSpaParams 27 28 /** 29 * Activity used as a bridge to [SpaActivity]. 30 * 31 * Since [SpaActivity] is not exported, [SpaActivity] could not be the target activity of 32 * <activity-alias>, otherwise all its pages will be exported. 33 * So need this bridge activity to sit in the middle of <activity-alias> and [SpaActivity]. 34 */ 35 class SpaBridgeActivity : Activity() { onCreatenull36 override fun onCreate(savedInstanceState: Bundle?) { 37 super.onCreate(savedInstanceState) 38 startSpaActivityFromBridge() 39 finish() 40 } 41 42 companion object { <lambda>null43 fun Activity.startSpaActivityFromBridge(destinationFactory: (String) -> String? = { it }) { 44 val (destination, highlightMenuKey) = getDestination(destinationFactory) ?: return 45 val intent = Intent(this, SpaActivity::class.java) 46 .appendSpaParams( 47 destination = destination, 48 sessionName = SESSION_EXTERNAL, 49 ) 50 if (!ActivityEmbeddingUtils.isEmbeddingActivityEnabled(this) || 51 !tryStartMultiPaneDeepLink(intent, highlightMenuKey) 52 ) { 53 startActivity(intent) 54 } 55 } 56 } 57 } 58