diff options
author | 2025-02-05 02:47:01 -0800 | |
---|---|---|
committer | 2025-02-05 02:47:01 -0800 | |
commit | 97a457c024e49b023ad58d0dd01b09f4745282f5 (patch) | |
tree | 4df86d0bd62c7c00238c14fc6e001cd05cadd99a /packages/SettingsLib/src | |
parent | 1e17cbab460d64e0c56e064cbd612a6268ecdec0 (diff) | |
parent | 29c4c58b0a2b33ea235c8df83d15d28bb683fcd7 (diff) |
Merge "Introduce an utility class in SettingsLib to create an intent to the supervision settings page." into main
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 + } +} |