diff options
Diffstat (limited to 'packages/SettingsLib/src')
-rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/supervision/OWNERS | 1 | ||||
-rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/supervision/SupervisionIntentProvider.kt | 44 |
2 files changed, 45 insertions, 0 deletions
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 + } +} |