Merge "Hide private space settings app post setup" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
d9b417cd72
@@ -32,14 +32,12 @@ import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.content.pm.ShortcutManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.Flags;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.Settings.CreateShortcutActivity;
|
||||
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
|
||||
import com.android.settings.homepage.DeepLinkHomepageActivity;
|
||||
import com.android.settings.search.SearchStateReceiver;
|
||||
@@ -49,7 +47,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Listens to {@link Intent.ACTION_PRE_BOOT_COMPLETED} and {@link Intent.ACTION_USER_INITIALIZED}
|
||||
* Listens to {@link Intent.ACTION_PRE_BOOT_COMPLETED} and {@link Intent.ACTION_USER_INITIALIZE}
|
||||
* performs setup steps for a managed profile (disables the launcher icon of the Settings app,
|
||||
* adds cross-profile intent filters for the appropriate Settings activities), disables the
|
||||
* webview setting for non-admin users, updates the intent flags for any existing shortcuts and
|
||||
@@ -68,7 +66,6 @@ public class SettingsInitialize extends BroadcastReceiver {
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
managedProfileSetup(context, pm, broadcast, userInfo);
|
||||
cloneProfileSetup(context, pm, userInfo);
|
||||
privateProfileSetup(context, pm, userInfo);
|
||||
webviewSettingSetup(context, pm, userInfo);
|
||||
ThreadUtils.postOnBackgroundThread(() -> refreshExistingShortcuts(context));
|
||||
enableTwoPaneDeepLinkActivityIfNecessary(pm, context);
|
||||
@@ -106,7 +103,7 @@ public class SettingsInitialize extends BroadcastReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
disableComponentsToHideSettings(context, pm);
|
||||
Utils.disableComponentsToHideSettings(context, pm);
|
||||
}
|
||||
|
||||
private void cloneProfileSetup(Context context, PackageManager pm, UserInfo userInfo) {
|
||||
@@ -114,31 +111,7 @@ public class SettingsInitialize extends BroadcastReceiver {
|
||||
return;
|
||||
}
|
||||
|
||||
disableComponentsToHideSettings(context, pm);
|
||||
}
|
||||
|
||||
private void privateProfileSetup(Context context, PackageManager pm, UserInfo userInfo) {
|
||||
if (Flags.allowPrivateProfile()
|
||||
&& android.multiuser.Flags.enablePrivateSpaceFeatures()) {
|
||||
if (userInfo == null || !userInfo.isPrivateProfile()) {
|
||||
return;
|
||||
}
|
||||
|
||||
disableComponentsToHideSettings(context, pm);
|
||||
}
|
||||
}
|
||||
|
||||
private void disableComponentsToHideSettings(Context context, PackageManager pm) {
|
||||
// Disable settings app launcher icon
|
||||
disableComponent(pm, new ComponentName(context, Settings.class));
|
||||
|
||||
//Disable Shortcut picker
|
||||
disableComponent(pm, new ComponentName(context, CreateShortcutActivity.class));
|
||||
}
|
||||
|
||||
private void disableComponent(PackageManager pm, ComponentName componentName) {
|
||||
pm.setComponentEnabledSetting(componentName,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||
Utils.disableComponentsToHideSettings(context, pm);
|
||||
}
|
||||
|
||||
// Disable WebView Setting if the current user is not an admin
|
||||
|
@@ -1464,4 +1464,22 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the launcher icon and shortcut picker component for the Settings app corresponding
|
||||
* to the context user.
|
||||
*/
|
||||
public static void disableComponentsToHideSettings(@NonNull Context context,
|
||||
@NonNull PackageManager pm) {
|
||||
// Disable settings app launcher icon
|
||||
disableComponent(pm, new ComponentName(context, Settings.class));
|
||||
|
||||
//Disable Shortcut picker
|
||||
disableComponent(pm, new ComponentName(context, Settings.CreateShortcutActivity.class));
|
||||
}
|
||||
|
||||
private static void disableComponent(PackageManager pm, ComponentName componentName) {
|
||||
pm.setComponentEnabledSetting(componentName,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.IntentSender;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.Flags;
|
||||
import android.os.UserHandle;
|
||||
@@ -44,6 +45,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -129,6 +131,7 @@ public class PrivateSpaceMaintainer {
|
||||
resetPrivateSpaceSettings();
|
||||
setUserSetupComplete();
|
||||
setSkipFirstUseHints();
|
||||
disableComponentsToHidePrivateSpaceSettings();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -356,6 +359,24 @@ public class PrivateSpaceMaintainer {
|
||||
1, mUserHandle.getIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the launcher icon and shortcut picker component for the Settings app instance
|
||||
* inside the private space
|
||||
*/
|
||||
@GuardedBy("this")
|
||||
private void disableComponentsToHidePrivateSpaceSettings() {
|
||||
if (mUserHandle == null) {
|
||||
Log.e(TAG, "User handle null while hiding settings icon");
|
||||
return;
|
||||
}
|
||||
|
||||
Context privateSpaceUserContext = mContext.createContextAsUser(mUserHandle, /* flags */ 0);
|
||||
PackageManager packageManager = privateSpaceUserContext.getPackageManager();
|
||||
|
||||
Log.d(TAG, "Hiding settings app launcher icon for " + mUserHandle);
|
||||
Utils.disableComponentsToHideSettings(privateSpaceUserContext, packageManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the SKIP_FIRST_USE_HINTS for private profile so that the first launch of an app in
|
||||
* private space will not display introductory hints.
|
||||
|
@@ -33,8 +33,10 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.IActivityManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Flags;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserManager;
|
||||
@@ -432,6 +434,36 @@ public class PrivateSpaceMaintainerTest {
|
||||
assertThat(getSecureSkipFirstUseHints()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPrivateSpace_psDoesNotExist_setsPrivateSpaceSettingsComponentDisabled() {
|
||||
mSetFlagsRule.enableFlags(
|
||||
android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
|
||||
assumeTrue(mContext.getSystemService(UserManager.class).canAddPrivateProfile());
|
||||
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||
PrivateSpaceMaintainer.getInstance(mContext);
|
||||
privateSpaceMaintainer.createPrivateSpace();
|
||||
assertThat(privateSpaceMaintainer.getPrivateProfileHandle()).isNotNull();
|
||||
Context privateSpaceUserContext = mContext.createContextAsUser(
|
||||
privateSpaceMaintainer.getPrivateProfileHandle(),
|
||||
/* flags */ 0);
|
||||
|
||||
// Assert that private space settings launcher app icon is disabled
|
||||
ComponentName settingsComponentName = new ComponentName(privateSpaceUserContext,
|
||||
com.android.settings.Settings.class);
|
||||
int settingsComponentEnabledSetting = privateSpaceUserContext.getPackageManager()
|
||||
.getComponentEnabledSetting(settingsComponentName);
|
||||
assertThat(settingsComponentEnabledSetting)
|
||||
.isEqualTo(PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
|
||||
|
||||
// Assert that private space settings create shortcut activity is disabled
|
||||
ComponentName shortcutPickerComponentName = new ComponentName(privateSpaceUserContext,
|
||||
com.android.settings.Settings.CreateShortcutActivity.class);
|
||||
int settingsShortcutPickerEnabledSetting = privateSpaceUserContext.getPackageManager()
|
||||
.getComponentEnabledSetting(shortcutPickerComponentName);
|
||||
assertThat(settingsShortcutPickerEnabledSetting)
|
||||
.isEqualTo(PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPrivateSpace_pSExists_doesNotChangeSkipFirstUseHints() {
|
||||
mSetFlagsRule.enableFlags(
|
||||
|
Reference in New Issue
Block a user