Merge "Hide private space settings app post setup" into main

This commit is contained in:
Jigar Thakkar
2024-06-05 11:44:42 +00:00
committed by Android (Google) Code Review
4 changed files with 74 additions and 30 deletions

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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.