blob: 6729830ab6792b3f38c3a710bec6a6a586982269 [file] [log] [blame]
Manish Singh27c39872023-07-31 14:41:00 +01001/*
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
17package com.android.settings.privatespace;
18
19import android.app.PendingIntent;
Manish Singh27c39872023-07-31 14:41:00 +010020import android.content.Context;
21import android.content.Intent;
Manish Singh5aef6b62023-09-12 16:52:28 +010022import android.os.Flags;
Manish Singh27c39872023-07-31 14:41:00 +010023import android.os.UserManager;
24import android.safetycenter.SafetyEvent;
25import android.safetycenter.SafetySourceData;
26import android.safetycenter.SafetySourceStatus;
Manish Singh27c39872023-07-31 14:41:00 +010027import android.util.Log;
28
29import com.android.settings.R;
Manish Singh27c39872023-07-31 14:41:00 +010030import com.android.settings.safetycenter.SafetyCenterManagerWrapper;
Manish Singh27c39872023-07-31 14:41:00 +010031
32/** Private Space safety source for the Safety Center */
33public final class PrivateSpaceSafetySource {
34 public static final String SAFETY_SOURCE_ID = "AndroidPrivateSpace";
Manish Singh5aef6b62023-09-12 16:52:28 +010035 private static final String TAG = "PrivateSpaceSafetySrc";
Manish Singh27c39872023-07-31 14:41:00 +010036
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 Singh5aef6b62023-09-12 16:52:28 +010054 if (!Flags.allowPrivateProfile()) {
Manish Singh27c39872023-07-31 14:41:00 +010055 // 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) {
josephpv31b044e2023-10-04 18:14:20 +000086 Intent privateSpaceAuthenticationIntent =
87 new Intent(context, PrivateSpaceAuthenticationActivity.class)
88 .setIdentifier(SAFETY_SOURCE_ID);
Manish Singh27c39872023-07-31 14:41:00 +010089
90 return PendingIntent
91 .getActivity(
92 context,
93 /* requestCode */ 0,
josephpv31b044e2023-10-04 18:14:20 +000094 privateSpaceAuthenticationIntent,
Manish Singh27c39872023-07-31 14:41:00 +010095 PendingIntent.FLAG_IMMUTABLE);
96 }
97}