diff options
author | 2025-01-24 15:52:43 +0000 | |
---|---|---|
committer | 2025-02-04 12:40:24 +0000 | |
commit | 29c4c58b0a2b33ea235c8df83d15d28bb683fcd7 (patch) | |
tree | 96563cad93098317bb33ca30ec5e6003badc9c54 /packages/SettingsLib/src | |
parent | 2a3ba7dd108dab33c477961b932acff3ddd6beae (diff) |
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
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 + } +} |