Add Private Space settings page
This involves: 1. Adding a new page for PS settings under Security & Privacy 2. Integrating the PS safety source with SafetyCenter. Also, add the capability to create and delete PS from the page. Creation is temporary to help with prototyping, and will be removed finally. Screenshots: Private Space Entry point in Security & Privacy Settings: https://screenshot.googleplex.com/4VHxNekjhxZHJwF Private Space Settings page: https://screenshot.googleplex.com/3Raw4wuymTHTgtM Creating Private Space: https://screenshot.googleplex.com/3dvzAH6V4kQmuYf Private Space created: https://screenshot.googleplex.com/Aj7nnF9uuUCa9Q5 Design doc: https://docs.google.com/document/d/1CdjUjAE84-5ZEPRIfw5KYFjLVHtEZxc_sF0w95su8DA/edit?usp=sharing&resourcekey=0-dAACT9HRexY1IyoxMmkVlw Bug: 286539356 Bug: 293569406 Test: manual Test: atest DeletePrivateSpaceControllerTest Test: atest UseOneLockControllerTest Test: atest HidePrivateSpaceControllerTest Change-Id: I9caf8e04e7fb2df36e60f607225e2931988ee692
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserManager;
|
||||
import android.safetycenter.SafetyEvent;
|
||||
import android.safetycenter.SafetySourceData;
|
||||
import android.safetycenter.SafetySourceStatus;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.safetycenter.SafetyCenterManagerWrapper;
|
||||
import com.android.settingslib.transition.SettingsTransitionHelper;
|
||||
|
||||
/** 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 = "PrivateSpaceSafetySource";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Check the profile type - we don't want to show this for anything other than primary user.
|
||||
UserManager userManager = context.getSystemService(UserManager.class);
|
||||
if (userManager != null && !userManager.isMainUser()) {
|
||||
Log.i(TAG, "setSafetySourceData not main user");
|
||||
return;
|
||||
}
|
||||
|
||||
// Temporary workaround to help prevent the PS Settings showing up in droidfood builds.
|
||||
// TODO(b/295516544): remove this when the trunk stable feature flag for PS is available.
|
||||
if (!FeatureFlagUtils.isEnabled(context,
|
||||
FeatureFlagUtils.SETTINGS_PRIVATE_SPACE_SETTINGS)) {
|
||||
// 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 privateSpaceDashboardIntent = new SubSettingLauncher(context)
|
||||
.setDestination(PrivateSpaceDashboardFragment.class.getName())
|
||||
.setTransitionType(SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE)
|
||||
.setSourceMetricsCategory(SettingsEnums.PRIVATE_SPACE_SETTINGS)
|
||||
.toIntent()
|
||||
.setIdentifier(SAFETY_SOURCE_ID);
|
||||
|
||||
return PendingIntent
|
||||
.getActivity(
|
||||
context,
|
||||
/* requestCode */ 0,
|
||||
privateSpaceDashboardIntent,
|
||||
PendingIntent.FLAG_IMMUTABLE);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user