From 29c4c58b0a2b33ea235c8df83d15d28bb683fcd7 Mon Sep 17 00:00:00 2001 From: Vitor Carvalho Date: Fri, 24 Jan 2025 15:52:43 +0000 Subject: Introduce an utility class in SettingsLib to create an intent to the supervision settings page. The intent of this API is to replace PO dependencies such as the one in EnterprisePrivacyFeatureProviderImpl. Bug: 382038391 Flag: EXEMPT unreachable code Test: atest SupervisionIntentProviderTest Change-Id: Ieb56b6ba188d2793b929c9ac4a4ba671b6a97339 --- .../src/com/android/settingslib/supervision/OWNERS | 1 + .../supervision/SupervisionIntentProvider.kt | 44 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 packages/SettingsLib/src/com/android/settingslib/supervision/OWNERS create mode 100644 packages/SettingsLib/src/com/android/settingslib/supervision/SupervisionIntentProvider.kt (limited to 'packages/SettingsLib/src') diff --git a/packages/SettingsLib/src/com/android/settingslib/supervision/OWNERS b/packages/SettingsLib/src/com/android/settingslib/supervision/OWNERS new file mode 100644 index 000000000000..04e7058b4384 --- /dev/null +++ b/packages/SettingsLib/src/com/android/settingslib/supervision/OWNERS @@ -0,0 +1 @@ +file:platform/frameworks/base:/core/java/android/app/supervision/OWNERS diff --git a/packages/SettingsLib/src/com/android/settingslib/supervision/SupervisionIntentProvider.kt b/packages/SettingsLib/src/com/android/settingslib/supervision/SupervisionIntentProvider.kt new file mode 100644 index 000000000000..749c2edba4d4 --- /dev/null +++ b/packages/SettingsLib/src/com/android/settingslib/supervision/SupervisionIntentProvider.kt @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settingslib.supervision + +import android.app.supervision.SupervisionManager +import android.content.Context +import android.content.Intent + +/** Helper class meant to provide an intent to launch the supervision settings page. */ +object SupervisionIntentProvider { + private const val ACTION_SHOW_PARENTAL_CONTROLS = "android.settings.SHOW_PARENTAL_CONTROLS" + + /** + * Returns an [Intent] to the supervision settings page or null if supervision is disabled or + * the intent is not resolvable. + */ + @JvmStatic + fun getSettingsIntent(context: Context): Intent? { + val supervisionManager = context.getSystemService(SupervisionManager::class.java) + val supervisionAppPackage = supervisionManager?.activeSupervisionAppPackage ?: return null + + val intent = + Intent(ACTION_SHOW_PARENTAL_CONTROLS) + .setPackage(supervisionAppPackage) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + val activities = + context.packageManager.queryIntentActivitiesAsUser(intent, 0, context.userId) + return if (activities.isNotEmpty()) intent else null + } +} -- cgit v1.2.3-59-g8ed1b