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.content.Context 20 import android.content.Intent 21 import android.os.Bundle 22 import android.util.Log 23 import androidx.annotation.VisibleForTesting 24 import com.android.settings.spa.app.appinfo.AppInfoSettingsProvider 25 import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin 26 import com.android.settingslib.spa.framework.BrowseActivity 27 import com.android.settingslib.spa.framework.common.SettingsPage 28 import com.android.settingslib.spa.framework.util.SESSION_BROWSE 29 import com.android.settingslib.spa.framework.util.appendSpaParams 30 import com.google.android.setupcompat.util.WizardManagerHelper 31 32 class SpaActivity : BrowseActivity() { isPageEnablednull33 override fun isPageEnabled(page: SettingsPage) = 34 super.isPageEnabled(page) && !isSuwAndPageBlocked(page.sppName) 35 36 override fun onCreate(savedInstanceState: Bundle?) { 37 super.onCreate(savedInstanceState) 38 lifecycle.addObserver(HideNonSystemOverlayMixin(this)) 39 } 40 41 companion object { 42 private const val TAG = "SpaActivity" 43 44 /** The pages that blocked from SUW. */ 45 private val SuwBlockedPages = setOf(AppInfoSettingsProvider.name) 46 47 @VisibleForTesting Contextnull48 fun Context.isSuwAndPageBlocked(name: String): Boolean = 49 if (name in SuwBlockedPages && !WizardManagerHelper.isDeviceProvisioned(this)) { 50 Log.w(TAG, "$name blocked before SUW completed.") 51 true 52 } else { 53 false 54 } 55 56 @JvmStatic Contextnull57 fun Context.startSpaActivity(destination: String) { 58 val intent = Intent(this, SpaActivity::class.java) 59 .appendSpaParams(destination = destination) 60 .appendSpaParams(sessionName = SESSION_BROWSE) 61 startActivity(intent) 62 } 63 } 64 } 65