Manish Singh | 27c3987 | 2023-07-31 14:41:00 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 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.privatespace; |
| 18 | |
| 19 | import android.app.PendingIntent; |
Manish Singh | 27c3987 | 2023-07-31 14:41:00 +0100 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
Manish Singh | 5aef6b6 | 2023-09-12 16:52:28 +0100 | [diff] [blame] | 22 | import android.os.Flags; |
Manish Singh | 27c3987 | 2023-07-31 14:41:00 +0100 | [diff] [blame] | 23 | import android.os.UserManager; |
| 24 | import android.safetycenter.SafetyEvent; |
| 25 | import android.safetycenter.SafetySourceData; |
| 26 | import android.safetycenter.SafetySourceStatus; |
Manish Singh | 27c3987 | 2023-07-31 14:41:00 +0100 | [diff] [blame] | 27 | import android.util.Log; |
| 28 | |
| 29 | import com.android.settings.R; |
Manish Singh | 27c3987 | 2023-07-31 14:41:00 +0100 | [diff] [blame] | 30 | import com.android.settings.safetycenter.SafetyCenterManagerWrapper; |
Manish Singh | 27c3987 | 2023-07-31 14:41:00 +0100 | [diff] [blame] | 31 | |
| 32 | /** Private Space safety source for the Safety Center */ |
| 33 | public final class PrivateSpaceSafetySource { |
| 34 | public static final String SAFETY_SOURCE_ID = "AndroidPrivateSpace"; |
Manish Singh | 5aef6b6 | 2023-09-12 16:52:28 +0100 | [diff] [blame] | 35 | private static final String TAG = "PrivateSpaceSafetySrc"; |
Manish Singh | 27c3987 | 2023-07-31 14:41:00 +0100 | [diff] [blame] | 36 | |
| 37 | private PrivateSpaceSafetySource() {} |
| 38 | |
| 39 | /** Sets lock screen safety data for Safety Center. */ |
| 40 | public static void setSafetySourceData(Context context, |
| 41 | SafetyEvent safetyEvent) { |
| 42 | if (!SafetyCenterManagerWrapper.get().isEnabled(context)) { |
| 43 | Log.i(TAG, "Safety Center disabled"); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | // Check the profile type - we don't want to show this for anything other than primary user. |
| 48 | UserManager userManager = context.getSystemService(UserManager.class); |
| 49 | if (userManager != null && !userManager.isMainUser()) { |
| 50 | Log.i(TAG, "setSafetySourceData not main user"); |
| 51 | return; |
| 52 | } |
| 53 | |
Manish Singh | 5aef6b6 | 2023-09-12 16:52:28 +0100 | [diff] [blame] | 54 | if (!Flags.allowPrivateProfile()) { |
Manish Singh | 27c3987 | 2023-07-31 14:41:00 +0100 | [diff] [blame] | 55 | // Setting null safetySourceData so that an old entry gets cleared out and this way |
| 56 | // provide a response since SC always expects one on rescan. |
| 57 | SafetyCenterManagerWrapper.get().setSafetySourceData( |
| 58 | context, |
| 59 | SAFETY_SOURCE_ID, |
| 60 | /* safetySourceData */ null, |
| 61 | safetyEvent |
| 62 | ); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | PendingIntent pendingIntent = getPendingIntentForPsDashboard(context); |
| 67 | |
| 68 | SafetySourceStatus status = new SafetySourceStatus.Builder( |
| 69 | context.getString(R.string.private_space_title), |
| 70 | context.getString(R.string.private_space_summary), |
| 71 | SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED) |
| 72 | .setPendingIntent(pendingIntent).build(); |
| 73 | SafetySourceData safetySourceData = |
| 74 | new SafetySourceData.Builder().setStatus(status).build(); |
| 75 | |
| 76 | Log.d(TAG, "Setting safety source data"); |
| 77 | SafetyCenterManagerWrapper.get().setSafetySourceData( |
| 78 | context, |
| 79 | SAFETY_SOURCE_ID, |
| 80 | safetySourceData, |
| 81 | safetyEvent |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | private static PendingIntent getPendingIntentForPsDashboard(Context context) { |
josephpv | 31b044e | 2023-10-04 18:14:20 +0000 | [diff] [blame] | 86 | Intent privateSpaceAuthenticationIntent = |
| 87 | new Intent(context, PrivateSpaceAuthenticationActivity.class) |
| 88 | .setIdentifier(SAFETY_SOURCE_ID); |
Manish Singh | 27c3987 | 2023-07-31 14:41:00 +0100 | [diff] [blame] | 89 | |
| 90 | return PendingIntent |
| 91 | .getActivity( |
| 92 | context, |
| 93 | /* requestCode */ 0, |
josephpv | 31b044e | 2023-10-04 18:14:20 +0000 | [diff] [blame] | 94 | privateSpaceAuthenticationIntent, |
Manish Singh | 27c3987 | 2023-07-31 14:41:00 +0100 | [diff] [blame] | 95 | PendingIntent.FLAG_IMMUTABLE); |
| 96 | } |
| 97 | } |