diff --git a/flags/src/com/android/launcher3/FeatureFlagsImpl.java b/flags/src/com/android/launcher3/FeatureFlagsImpl.java index e8314d8f87..b8cfae5e3a 100644 --- a/flags/src/com/android/launcher3/FeatureFlagsImpl.java +++ b/flags/src/com/android/launcher3/FeatureFlagsImpl.java @@ -152,19 +152,19 @@ public final class FeatureFlagsImpl implements FeatureFlags { try { var properties = DeviceConfigHelper.Companion.getPrefs(); enablePrivateSpace = - properties.getBoolean(Flags.FLAG_ENABLE_PRIVATE_SPACE, true); + properties.getBoolean(Flags.FLAG_ENABLE_PRIVATE_SPACE, BuildCompat.isAtLeastU()); privateSpaceAddFloatingMaskView = - properties.getBoolean(Flags.FLAG_PRIVATE_SPACE_ADD_FLOATING_MASK_VIEW, false); + properties.getBoolean(Flags.FLAG_PRIVATE_SPACE_ADD_FLOATING_MASK_VIEW, BuildCompat.isAtLeastU()); privateSpaceAnimation = - properties.getBoolean(Flags.FLAG_PRIVATE_SPACE_ANIMATION, true); + properties.getBoolean(Flags.FLAG_PRIVATE_SPACE_ANIMATION, BuildCompat.isAtLeastU()); privateSpaceAppInstallerButton = - properties.getBoolean(Flags.FLAG_PRIVATE_SPACE_APP_INSTALLER_BUTTON, true); + properties.getBoolean(Flags.FLAG_PRIVATE_SPACE_APP_INSTALLER_BUTTON, BuildCompat.isAtLeastU()); privateSpaceRestrictAccessibilityDrag = - properties.getBoolean(Flags.FLAG_PRIVATE_SPACE_RESTRICT_ACCESSIBILITY_DRAG, true); + properties.getBoolean(Flags.FLAG_PRIVATE_SPACE_RESTRICT_ACCESSIBILITY_DRAG, BuildCompat.isAtLeastU()); privateSpaceRestrictItemDrag = - properties.getBoolean(Flags.FLAG_PRIVATE_SPACE_RESTRICT_ITEM_DRAG, true); + properties.getBoolean(Flags.FLAG_PRIVATE_SPACE_RESTRICT_ITEM_DRAG, BuildCompat.isAtLeastU()); privateSpaceSysAppsSeparation = - properties.getBoolean(Flags.FLAG_PRIVATE_SPACE_SYS_APPS_SEPARATION, true); + properties.getBoolean(Flags.FLAG_PRIVATE_SPACE_SYS_APPS_SEPARATION, BuildCompat.isAtLeastU()); } catch (NullPointerException e) { throw new RuntimeException( "Cannot read value from namespace launcher_search " diff --git a/lawnchair/src/app/lawnchair/allapps/LawnchairAlphabeticalAppsList.kt b/lawnchair/src/app/lawnchair/allapps/LawnchairAlphabeticalAppsList.kt index 9fd9ea0612..e9ccdd6f5f 100644 --- a/lawnchair/src/app/lawnchair/allapps/LawnchairAlphabeticalAppsList.kt +++ b/lawnchair/src/app/lawnchair/allapps/LawnchairAlphabeticalAppsList.kt @@ -19,7 +19,7 @@ class LawnchairAlphabeticalAppsList( context: T, appsStore: AllAppsStore, workProfileManager: WorkProfileManager?, - privateProfileManager: PrivateProfileManager, + privateProfileManager: PrivateProfileManager?, ) : AlphabeticalAppsList(context, appsStore, workProfileManager, privateProfileManager) where T : Context, T : ActivityContext { diff --git a/quickstep/AndroidManifest.xml b/quickstep/AndroidManifest.xml index e913c58f8e..e0aae7bd06 100644 --- a/quickstep/AndroidManifest.xml +++ b/quickstep/AndroidManifest.xml @@ -47,6 +47,7 @@ from being visible via APIs, e.g. private profile. --> + - + com.android.launcher3.uioverrides.SystemApiWrapper diff --git a/quickstep/src/com/android/launcher3/uioverrides/SystemApiWrapper.kt b/quickstep/src/com/android/launcher3/uioverrides/SystemApiWrapper.kt new file mode 100644 index 0000000000..50c9ae0652 --- /dev/null +++ b/quickstep/src/com/android/launcher3/uioverrides/SystemApiWrapper.kt @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2024 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.launcher3.uioverrides + +import android.app.ActivityOptions +import android.app.PendingIntent +import android.app.role.RoleManager +import android.content.Context +import android.content.IIntentReceiver +import android.content.IIntentSender +import android.content.Intent +import android.content.pm.ActivityInfo +import android.content.pm.LauncherActivityInfo +import android.content.pm.LauncherApps +import android.content.pm.ShortcutInfo +import android.os.Build +import android.os.Bundle +import android.os.IBinder +import android.os.UserHandle +import android.os.UserManager +import android.util.ArrayMap +import android.widget.Toast +import android.window.RemoteTransition +import androidx.annotation.RequiresApi +import app.lawnchair.LawnchairApp +import com.android.launcher3.Flags.enablePrivateSpace +import com.android.launcher3.Flags.enablePrivateSpaceInstallShortcut +import com.android.launcher3.Flags.privateSpaceAppInstallerButton +import com.android.launcher3.Flags.privateSpaceSysAppsSeparation +import com.android.launcher3.R +import com.android.launcher3.Utilities +import com.android.launcher3.proxy.ProxyActivityStarter +import com.android.launcher3.util.ApiWrapper +import com.android.launcher3.util.Executors +import com.android.launcher3.util.StartActivityParams +import com.android.launcher3.util.UserIconInfo +import com.android.quickstep.util.FadeOutRemoteTransition + +/** A wrapper for the hidden API calls */ +open class SystemApiWrapper(context: Context?) : ApiWrapper(context) { + + override fun getPersons(si: ShortcutInfo) = si.persons ?: Utilities.EMPTY_PERSON_ARRAY + + override fun getActivityOverrides(): Map { + return try { + mContext.getSystemService(LauncherApps::class.java)!!.activityOverrides + } catch (t: Throwable) { + super.activityOverrides + } + } + + override fun createFadeOutAnimOptions(): ActivityOptions { + return try { + ActivityOptions.makeBasic().apply { + remoteTransition = RemoteTransition(FadeOutRemoteTransition()) + } + } catch (t: Throwable) { + super.createFadeOutAnimOptions() + } + } + + @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) + override fun queryAllUsers(): Map { + if (!enablePrivateSpace() || !LawnchairApp.isRecentsEnabled) { + return super.queryAllUsers() + } + val users = ArrayMap() + mContext.getSystemService(UserManager::class.java)!!.userProfiles?.forEach { user -> + mContext.getSystemService(LauncherApps::class.java)!!.getLauncherUserInfo(user)?.apply { + users[user] = + UserIconInfo( + user, + when (userType) { + UserManager.USER_TYPE_PROFILE_MANAGED -> UserIconInfo.TYPE_WORK + UserManager.USER_TYPE_PROFILE_CLONE -> UserIconInfo.TYPE_CLONED + UserManager.USER_TYPE_PROFILE_PRIVATE -> UserIconInfo.TYPE_PRIVATE + else -> UserIconInfo.TYPE_MAIN + }, + userSerialNumber.toLong() + ) + } + } + return users + } + + @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM) + override fun getPreInstalledSystemPackages(user: UserHandle): List = + if (enablePrivateSpace() && privateSpaceSysAppsSeparation()) + mContext + .getSystemService(LauncherApps::class.java)!! + .getPreInstalledSystemPackages(user) + else ArrayList() + + override fun getAppMarketActivityIntent(packageName: String, user: UserHandle): Intent = + if ( + enablePrivateSpace() && + (privateSpaceAppInstallerButton() || enablePrivateSpaceInstallShortcut()) + ) + ProxyActivityStarter.getLaunchIntent( + mContext, + StartActivityParams(null as PendingIntent?, 0).apply { + intentSender = + mContext + .getSystemService(LauncherApps::class.java)!! + .getAppMarketActivityIntent(packageName, user) + options = + ActivityOptions.makeBasic() + .setPendingIntentBackgroundActivityStartMode( + ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED + ) + .toBundle() + requireActivityResult = false + } + ) + else super.getAppMarketActivityIntent(packageName, user) + + /** Returns an intent which can be used to open Private Space Settings. */ + override fun getPrivateSpaceSettingsIntent(): Intent? = + if (enablePrivateSpace()) + ProxyActivityStarter.getLaunchIntent( + mContext, + StartActivityParams(null as PendingIntent?, 0).apply { + intentSender = + mContext + .getSystemService(LauncherApps::class.java) + ?.privateSpaceSettingsIntent ?: return null + options = + ActivityOptions.makeBasic() + .setPendingIntentBackgroundActivityStartMode( + ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED + ) + .toBundle() + requireActivityResult = false + } + ) + else null + + override fun isNonResizeableActivity(lai: LauncherActivityInfo): Boolean { + return try { + lai.activityInfo.resizeMode == ActivityInfo.RESIZE_MODE_UNRESIZEABLE + } catch (t: Throwable) { + super.isNonResizeableActivity(lai) + } + } + + /** + * Starts an Activity which can be used to set this Launcher as the HOME app, via a consent + * screen. In case the consent screen cannot be shown, or the user does not set current Launcher + * as HOME app, a toast asking the user to do the latter is shown. + */ + override fun assignDefaultHomeRole(context: Context) { + try { + val roleManager = context.getSystemService(RoleManager::class.java) + if ( + (roleManager!!.isRoleAvailable(RoleManager.ROLE_HOME) && + !roleManager.isRoleHeld(RoleManager.ROLE_HOME)) + ) { + val roleRequestIntent = roleManager.createRequestRoleIntent(RoleManager.ROLE_HOME) + val pendingIntent = + PendingIntent( + object : IIntentSender.Stub() { + override fun send( + code: Int, + intent: Intent, + resolvedType: String?, + allowlistToken: IBinder?, + finishedReceiver: IIntentReceiver?, + requiredPermission: String?, + options: Bundle? + ) { + if (code != -1) { + Executors.MAIN_EXECUTOR.execute { + Toast.makeText( + context, + context.getString( + R.string.set_default_home_app, + context.getString(R.string.derived_app_name) + ), + Toast.LENGTH_LONG + ) + .show() + } + } + } + } + ) + val params = StartActivityParams(pendingIntent, 0) + params.intent = roleRequestIntent + context.startActivity(ProxyActivityStarter.getLaunchIntent(context, params)) + } + } catch (t: Throwable) { + super.assignDefaultHomeRole(context) + } + } +} diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java index b2311d22d7..e526114105 100644 --- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java @@ -291,9 +291,9 @@ public class ActivityAllAppsContainerView mAH.set(AdapterHolder.MAIN, new AdapterHolder(AdapterHolder.MAIN, new LawnchairAlphabeticalAppsList<>(mActivityContext, mAllAppsStore, null, mPrivateProfileManager))); mAH.set(AdapterHolder.WORK, new AdapterHolder(AdapterHolder.WORK, - new LawnchairAlphabeticalAppsList<>(mActivityContext, mAllAppsStore, mWorkManager, mPrivateProfileManager))); + new LawnchairAlphabeticalAppsList<>(mActivityContext, mAllAppsStore, mWorkManager, null))); mAH.set(SEARCH, new AdapterHolder(SEARCH, - new LawnchairAlphabeticalAppsList<>(mActivityContext, mAllAppsStore, null, mPrivateProfileManager))); + new LawnchairAlphabeticalAppsList<>(mActivityContext, mAllAppsStore, null, null))); getLayoutInflater().inflate(R.layout.all_apps_content, this); mHeader = findViewById(R.id.all_apps_header); diff --git a/src/com/android/launcher3/model/data/WorkspaceItemInfo.java b/src/com/android/launcher3/model/data/WorkspaceItemInfo.java index 3b3b4eb240..a741bb8c42 100644 --- a/src/com/android/launcher3/model/data/WorkspaceItemInfo.java +++ b/src/com/android/launcher3/model/data/WorkspaceItemInfo.java @@ -206,7 +206,7 @@ public class WorkspaceItemInfo extends ItemInfoWithIcon { } if (Utilities.ATLEAST_Q) { - Person[] persons = ApiWrapper.getPersons(shortcutInfo); + Person[] persons = ApiWrapper.INSTANCE.get(context).getPersons(shortcutInfo); personKeys = persons.length == 0 ? Utilities.EMPTY_STRING_ARRAY : Arrays.stream(persons).map(Person::getKey).sorted().toArray(String[]::new); } diff --git a/src/com/android/launcher3/util/ApiWrapper.java b/src/com/android/launcher3/util/ApiWrapper.java index 24d1b6e49b..2458afcb44 100644 --- a/src/com/android/launcher3/util/ApiWrapper.java +++ b/src/com/android/launcher3/util/ApiWrapper.java @@ -25,14 +25,18 @@ import android.app.role.RoleManager; import android.content.Context; import android.content.Intent; import android.content.pm.LauncherActivityInfo; +import android.content.pm.LauncherApps; +import android.content.pm.LauncherUserInfo; import android.content.pm.ShortcutInfo; import android.graphics.drawable.ColorDrawable; import android.net.Uri; +import android.os.Build; import android.os.UserHandle; import android.os.UserManager; import android.util.ArrayMap; import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import com.android.launcher3.BuildConfig; import com.android.launcher3.Launcher; @@ -60,7 +64,7 @@ public class ApiWrapper implements ResourceBasedOverride, SafeCloseable { /** * Returns the list of persons associated with the provided shortcut info */ - public static Person[] getPersons(ShortcutInfo si) { + public Person[] getPersons(ShortcutInfo si) { return Utilities.EMPTY_PERSON_ARRAY; } @@ -90,10 +94,28 @@ public class ApiWrapper implements ResourceBasedOverride, SafeCloseable { // TODO: Migrate to a better platform API NoopDrawable d = new NoopDrawable(); boolean isWork = (d != mContext.getPackageManager().getUserBadgedIcon(d, user)); + + var launcherApps = mContext.getSystemService(LauncherApps.class); UserIconInfo info = new UserIconInfo( user, isWork ? UserIconInfo.TYPE_WORK : UserIconInfo.TYPE_MAIN, serial); + + if (launcherApps != null && Utilities.ATLEAST_U) { + LauncherUserInfo userInfo = launcherApps.getLauncherUserInfo(user); + if (userInfo != null) { + var userType = userInfo.getUserType(); + info = new UserIconInfo( + user, + userType.equals (UserManager.USER_TYPE_PROFILE_MANAGED) ? UserIconInfo.TYPE_WORK : + userType.equals (UserManager.USER_TYPE_PROFILE_CLONE) ? UserIconInfo.TYPE_CLONED : + userType.equals (UserManager.USER_TYPE_PROFILE_PRIVATE) ? UserIconInfo.TYPE_PRIVATE : + UserIconInfo.TYPE_MAIN, + serial + ); + } + } + users.put(user, info); } } @@ -145,14 +167,16 @@ public class ApiWrapper implements ResourceBasedOverride, SafeCloseable { * as HOME app, a toast asking the user to do the latter is shown. */ public void assignDefaultHomeRole(Context context) { - RoleManager roleManager = context.getSystemService(RoleManager.class); - assert roleManager != null; - if (roleManager.isRoleAvailable(RoleManager.ROLE_HOME) - && !roleManager.isRoleHeld(RoleManager.ROLE_HOME)) { - Intent roleRequestIntent = roleManager.createRequestRoleIntent( - RoleManager.ROLE_HOME); - Launcher launcher = Launcher.getLauncher(context); - launcher.startActivityForResult(roleRequestIntent, REQUEST_HOME_ROLE); + RoleManager roleManager = null; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + roleManager = context.getSystemService(RoleManager.class); + if (roleManager != null && roleManager.isRoleAvailable (RoleManager.ROLE_HOME) + && !roleManager.isRoleHeld (RoleManager.ROLE_HOME)) { + Intent roleRequestIntent = roleManager.createRequestRoleIntent ( + RoleManager.ROLE_HOME); + Launcher launcher = Launcher.getLauncher (context); + launcher.startActivityForResult (roleRequestIntent , REQUEST_HOME_ROLE); + } } } @@ -170,4 +194,4 @@ public class ApiWrapper implements ResourceBasedOverride, SafeCloseable { return 1; } } -} +} \ No newline at end of file