[Large screen] Disable/enable DeepLinkHomepageActivity

This change enable/disable DeepLinkHomepageActivity according to
SplitController#isSplitSupported when receiving PRE_BOOT_COMPLETED.

PRE_BOOT_COMPLETED is an Intent which broadcasts once when the user
is booting after a system update.

Bug: 201236463
Bug: 201237323
Test: manual
      1. On a large screen device, Launcher -> Wallpaper & style
         Observe it uses intent ACTION_SETTINGS_LARGE_SCREEN_DEEP_LINK.
      2. On a small screen device, Launcher -> Wallpaper & style
         Observe it does NOT use intent ACTION_SETTINGS_LARGE_SCREEN_DEEP_LINK.
Change-Id: Icf6ab6d0cba38224c4b80276141d84a8468da760
This commit is contained in:
Arc Wang
2021-09-28 22:26:48 +08:00
parent 65faee72f5
commit 54f619dfb8

View File

@@ -34,11 +34,14 @@ import android.content.pm.ShortcutManager;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.window.embedding.SplitController;
import com.android.settings.Settings.CreateShortcutActivity; import com.android.settings.Settings.CreateShortcutActivity;
import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settingslib.utils.ThreadUtils; import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList; import java.util.ArrayList;
@@ -48,7 +51,8 @@ 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_INITIALIZED}
* 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, and updates the intent flags for any existing shortcuts. * webview setting for non-admin users, updates the intent flags for any existing shortcuts and
* enables DeepLinkHomepageActivity for large screen devices.
*/ */
public class SettingsInitialize extends BroadcastReceiver { public class SettingsInitialize extends BroadcastReceiver {
private static final String TAG = "Settings"; private static final String TAG = "Settings";
@@ -64,6 +68,7 @@ public class SettingsInitialize extends BroadcastReceiver {
managedProfileSetup(context, pm, broadcast, userInfo); managedProfileSetup(context, pm, broadcast, userInfo);
webviewSettingSetup(context, pm, userInfo); webviewSettingSetup(context, pm, userInfo);
ThreadUtils.postOnBackgroundThread(() -> refreshExistingShortcuts(context)); ThreadUtils.postOnBackgroundThread(() -> refreshExistingShortcuts(context));
enableTwoPaneDeepLinkActivityIfNecessary(pm, broadcast);
} }
private void managedProfileSetup(Context context, final PackageManager pm, Intent broadcast, private void managedProfileSetup(Context context, final PackageManager pm, Intent broadcast,
@@ -143,4 +148,17 @@ public class SettingsInitialize extends BroadcastReceiver {
} }
shortcutManager.updateShortcuts(updates); shortcutManager.updateShortcuts(updates);
} }
private void enableTwoPaneDeepLinkActivityIfNecessary(PackageManager pm, Intent intent) {
if (!TextUtils.equals(intent.getAction(), Intent.ACTION_PRE_BOOT_COMPLETED)) {
return;
}
final ComponentName deepLinkHome = new ComponentName(Utils.SETTINGS_PACKAGE_NAME,
SettingsHomepageActivity.ALIAS_DEEP_LINK);
final int enableState = SplitController.getInstance().isSplitSupported()
? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
pm.setComponentEnabledSetting(deepLinkHome, enableState, PackageManager.DONT_KILL_APP);
}
} }