Files
packages_apps_Settings/src/com/android/settings/privatespace/PrivateSpaceSafetySource.java
Himanshu Gupta 5e451db395 Disable PS entry point and Activity when PS is not allowed.
In this change we disable:
1. Security Center Entry point
2. PrivateSpaceAuthenticationActivity

when private profile is not present and cannot be added.

Additionally, the intent exposing PrivateSpaceAuthenticationActivity
is also non-exported and changed to a better name.

Bug: 328578044
Test: Manual build and flash
Change-Id: I13d298316c6d719d0b06e4969989ea1da83dd4c6
2024-03-22 13:44:23 +00:00

115 lines
4.5 KiB
Java

/*
* Copyright (C) 2023 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.settings.privatespace;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Flags;
import android.os.UserManager;
import android.safetycenter.SafetyEvent;
import android.safetycenter.SafetySourceData;
import android.safetycenter.SafetySourceStatus;
import android.util.Log;
import com.android.settings.R;
import com.android.settings.safetycenter.SafetyCenterManagerWrapper;
/** Private Space safety source for the Safety Center */
public final class PrivateSpaceSafetySource {
public static final String SAFETY_SOURCE_ID = "AndroidPrivateSpace";
private static final String TAG = "PrivateSpaceSafetySrc";
private PrivateSpaceSafetySource() {}
/** Sets lock screen safety data for Safety Center. */
public static void setSafetySourceData(Context context,
SafetyEvent safetyEvent) {
if (!SafetyCenterManagerWrapper.get().isEnabled(context)) {
Log.i(TAG, "Safety Center disabled");
return;
}
UserManager userManager = context.getSystemService(UserManager.class);
PrivateSpaceMaintainer privateSpaceMaintainer =
PrivateSpaceMaintainer.getInstance(context);
if (android.multiuser.Flags.enablePrivateSpaceFeatures()
&& android.multiuser.Flags.blockPrivateSpaceCreation()) {
// Do not add the entry point when
// -Private Profile is not present and
// -Private Profile cannot be added.
if (!privateSpaceMaintainer.doesPrivateSpaceExist()
&& userManager != null
&& !userManager.canAddPrivateProfile()) {
Log.i(TAG, "Private Space not allowed for user " + context.getUser());
return;
}
} else {
// Check the profile type - we don't want to show this for anything other than primary
// user.
if (userManager != null && !userManager.isMainUser()) {
Log.i(TAG, "setSafetySourceData not main user");
return;
}
}
if (!Flags.allowPrivateProfile()
|| !android.multiuser.Flags.enablePrivateSpaceFeatures()) {
// Setting null safetySourceData so that an old entry gets cleared out and this way
// provide a response since SC always expects one on rescan.
SafetyCenterManagerWrapper.get().setSafetySourceData(
context,
SAFETY_SOURCE_ID,
/* safetySourceData */ null,
safetyEvent
);
return;
}
PendingIntent pendingIntent = getPendingIntentForPsDashboard(context);
SafetySourceStatus status = new SafetySourceStatus.Builder(
context.getString(R.string.private_space_title),
context.getString(R.string.private_space_summary),
SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED)
.setPendingIntent(pendingIntent).build();
SafetySourceData safetySourceData =
new SafetySourceData.Builder().setStatus(status).build();
Log.d(TAG, "Setting safety source data");
SafetyCenterManagerWrapper.get().setSafetySourceData(
context,
SAFETY_SOURCE_ID,
safetySourceData,
safetyEvent
);
}
private static PendingIntent getPendingIntentForPsDashboard(Context context) {
Intent privateSpaceAuthenticationIntent =
new Intent(context, PrivateSpaceAuthenticationActivity.class)
.setIdentifier(SAFETY_SOURCE_ID);
return PendingIntent
.getActivity(
context,
/* requestCode */ 0,
privateSpaceAuthenticationIntent,
PendingIntent.FLAG_IMMUTABLE);
}
}