Hide private space settings app post setup
Currently, the changes to disable private space settings app component are located in SettiingsInitialize.java. These get triggered when ACTION_USER_INITIALIZE is received by the settings app inside the private profile user. However, we are stopping the private profile user at the end of the setup flow. This can lead to a scenario wherein ACTION_USER_INITIALIZE is relayed by the system server but not received by the private space settings app, since it was stopped. To over come this issue, we move the changes to disable the private space settings app component inside the private space setup flow (right after the user is created and started). Bug: 342165140 Test: atest PrivateSpaceMaintainerTest#createPrivateSpace_psDoesNotExist_setsPrivateSpaceSettingsComponentDisabled Flag: ACONFIG android.multiuser.enable_private_space_features NEXTFOOD Change-Id: Ib9baac1e9d835ea5a27c15d499e10615b84cf97b
This commit is contained in:
@@ -32,14 +32,12 @@ import android.content.pm.ResolveInfo;
|
|||||||
import android.content.pm.ShortcutInfo;
|
import android.content.pm.ShortcutInfo;
|
||||||
import android.content.pm.ShortcutManager;
|
import android.content.pm.ShortcutManager;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.os.Flags;
|
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.android.settings.Settings.CreateShortcutActivity;
|
|
||||||
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
|
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
|
||||||
import com.android.settings.homepage.DeepLinkHomepageActivity;
|
import com.android.settings.homepage.DeepLinkHomepageActivity;
|
||||||
import com.android.settings.search.SearchStateReceiver;
|
import com.android.settings.search.SearchStateReceiver;
|
||||||
@@ -49,7 +47,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
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,
|
* 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
|
* 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
|
* 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();
|
final PackageManager pm = context.getPackageManager();
|
||||||
managedProfileSetup(context, pm, broadcast, userInfo);
|
managedProfileSetup(context, pm, broadcast, userInfo);
|
||||||
cloneProfileSetup(context, pm, userInfo);
|
cloneProfileSetup(context, pm, userInfo);
|
||||||
privateProfileSetup(context, pm, userInfo);
|
|
||||||
webviewSettingSetup(context, pm, userInfo);
|
webviewSettingSetup(context, pm, userInfo);
|
||||||
ThreadUtils.postOnBackgroundThread(() -> refreshExistingShortcuts(context));
|
ThreadUtils.postOnBackgroundThread(() -> refreshExistingShortcuts(context));
|
||||||
enableTwoPaneDeepLinkActivityIfNecessary(pm, 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) {
|
private void cloneProfileSetup(Context context, PackageManager pm, UserInfo userInfo) {
|
||||||
@@ -114,31 +111,7 @@ public class SettingsInitialize extends BroadcastReceiver {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
disableComponentsToHideSettings(context, pm);
|
Utils.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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable WebView Setting if the current user is not an admin
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.IntentSender;
|
import android.content.IntentSender;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.os.Flags;
|
import android.os.Flags;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
@@ -43,6 +44,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.android.internal.annotations.GuardedBy;
|
import com.android.internal.annotations.GuardedBy;
|
||||||
|
import com.android.settings.Utils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -124,6 +126,7 @@ public class PrivateSpaceMaintainer {
|
|||||||
resetPrivateSpaceSettings();
|
resetPrivateSpaceSettings();
|
||||||
setUserSetupComplete();
|
setUserSetupComplete();
|
||||||
setSkipFirstUseHints();
|
setSkipFirstUseHints();
|
||||||
|
disableComponentsToHidePrivateSpaceSettings();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -351,6 +354,24 @@ public class PrivateSpaceMaintainer {
|
|||||||
1, mUserHandle.getIdentifier());
|
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
|
* 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.
|
* private space will not display introductory hints.
|
||||||
|
@@ -33,8 +33,10 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.IActivityManager;
|
import android.app.IActivityManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Flags;
|
import android.os.Flags;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
@@ -432,6 +434,36 @@ public class PrivateSpaceMaintainerTest {
|
|||||||
assertThat(getSecureSkipFirstUseHints()).isEqualTo(1);
|
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
|
@Test
|
||||||
public void createPrivateSpace_pSExists_doesNotChangeSkipFirstUseHints() {
|
public void createPrivateSpace_pSExists_doesNotChangeSkipFirstUseHints() {
|
||||||
mSetFlagsRule.enableFlags(
|
mSetFlagsRule.enableFlags(
|
||||||
|
Reference in New Issue
Block a user