UserAspectRatioManager call AtivityRecord#canBeUniversalResizeable
instead of duplicating the method locally. Fix: 374903057 Flag: EXEMPT same behavior Test: UserAspectRatioManagerTest Change-Id: I7b362bf9aaf06e1af0288e0ce8c43e7c3b3472e3
This commit is contained in:
@@ -33,10 +33,10 @@ import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_USER_ASPECT_RATIO
|
||||
|
||||
import static java.lang.Boolean.FALSE;
|
||||
|
||||
import android.app.ActivityTaskManager;
|
||||
import android.app.AppGlobals;
|
||||
import android.app.compat.CompatChanges;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.content.pm.LauncherApps;
|
||||
@@ -53,7 +53,6 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.window.flags.Flags;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
@@ -80,13 +79,15 @@ public class UserAspectRatioManager {
|
||||
private final Map<Integer, String> mUserAspectRatioMap;
|
||||
private final Map<Integer, CharSequence> mUserAspectRatioA11yMap;
|
||||
private final SparseIntArray mUserAspectRatioOrder;
|
||||
private final ActivityTaskManager mActivityTaskManager;
|
||||
|
||||
public UserAspectRatioManager(@NonNull Context context) {
|
||||
this(context, AppGlobals.getPackageManager());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
UserAspectRatioManager(@NonNull Context context, @NonNull IPackageManager pm) {
|
||||
UserAspectRatioManager(@NonNull Context context, @NonNull IPackageManager pm,
|
||||
@NonNull ActivityTaskManager activityTaskManager) {
|
||||
mContext = context;
|
||||
mIPm = pm;
|
||||
mUserAspectRatioA11yMap = new ArrayMap<>();
|
||||
@@ -94,8 +95,13 @@ public class UserAspectRatioManager {
|
||||
mUserAspectRatioMap = getUserMinAspectRatioMapping();
|
||||
mIgnoreActivityOrientationRequest = getValueFromDeviceConfig(
|
||||
"ignore_activity_orientation_request", false);
|
||||
mActivityTaskManager = activityTaskManager;
|
||||
|
||||
}
|
||||
|
||||
UserAspectRatioManager(@NonNull Context context, @NonNull IPackageManager pm) {
|
||||
this(context, pm, ActivityTaskManager.getInstance());
|
||||
}
|
||||
/**
|
||||
* Whether user aspect ratio settings is enabled for device.
|
||||
*/
|
||||
@@ -117,24 +123,6 @@ public class UserAspectRatioManager {
|
||||
? aspectRatio : USER_MIN_ASPECT_RATIO_UNSET;
|
||||
}
|
||||
|
||||
// TODO b/374903057 reuse method from ActivityRecord
|
||||
boolean isUniversalResizeable(@NonNull String packageName, int userId) {
|
||||
try {
|
||||
final ApplicationInfo info = mIPm.getApplicationInfo(
|
||||
packageName, 0 /* flags */, userId);
|
||||
if (info == null || info.category == ApplicationInfo.CATEGORY_GAME) {
|
||||
return false;
|
||||
}
|
||||
final boolean compatEnabled = Flags.universalResizableByDefault()
|
||||
&& info.isChangeEnabled(ActivityInfo.UNIVERSAL_RESIZABLE_BY_DEFAULT);
|
||||
return compatEnabled || mIgnoreActivityOrientationRequest;
|
||||
} catch (RemoteException e) {
|
||||
Log.e("UserAspectRatioManager", "Could not access application info for "
|
||||
+ packageName + ":\n" + e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return corresponding string for {@link PackageManager.UserMinAspectRatio} value
|
||||
*/
|
||||
@@ -249,12 +237,20 @@ public class UserAspectRatioManager {
|
||||
* or app is universal resizeable, and app has not opted-out from the treatment
|
||||
*/
|
||||
boolean isOverrideToFullscreenEnabled(String pkgName, int userId) {
|
||||
Boolean appAllowsOrientationOverride = readComponentProperty(mContext.getPackageManager(),
|
||||
pkgName, PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE);
|
||||
return hasAspectRatioOption(USER_MIN_ASPECT_RATIO_FULLSCREEN, pkgName)
|
||||
&& !FALSE.equals(appAllowsOrientationOverride)
|
||||
&& (isFullscreenCompatChangeEnabled(pkgName, userId)
|
||||
|| isUniversalResizeable(pkgName, userId));
|
||||
try {
|
||||
Boolean appAllowsOrientationOverride = readComponentProperty(
|
||||
mContext.getPackageManager(), pkgName,
|
||||
PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE);
|
||||
final ApplicationInfo info = mIPm.getApplicationInfo(pkgName, 0 /* flags */, userId);
|
||||
return hasAspectRatioOption(USER_MIN_ASPECT_RATIO_FULLSCREEN, pkgName)
|
||||
&& !FALSE.equals(appAllowsOrientationOverride)
|
||||
&& (isFullscreenCompatChangeEnabled(pkgName, userId)
|
||||
|| (info != null && mActivityTaskManager.canBeUniversalResizeable(info)));
|
||||
} catch (RemoteException e) {
|
||||
Log.e("UserAspectRatioManager", "Could not access application info for "
|
||||
+ pkgName + ":\n" + e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isFullscreenCompatChangeEnabled(String pkgName, int userId) {
|
||||
|
@@ -40,12 +40,14 @@ import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.ActivityTaskManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.IPackageManager;
|
||||
@@ -88,6 +90,7 @@ public class UserAspectRatioManagerTest {
|
||||
private String mOriginalFullscreenFlag;
|
||||
private IPackageManager mIPm;
|
||||
private PackageManager mPm;
|
||||
private ActivityTaskManager mActivityTaskManager;
|
||||
private List<LauncherActivityInfo> mLauncherActivities;
|
||||
|
||||
@Before
|
||||
@@ -98,13 +101,15 @@ public class UserAspectRatioManagerTest {
|
||||
mLauncherActivities = mock(List.class);
|
||||
mIPm = mock(IPackageManager.class);
|
||||
mPm = mock(PackageManager.class);
|
||||
mActivityTaskManager = mock(ActivityTaskManager.class);
|
||||
when(mActivityTaskManager.canBeUniversalResizeable(any())).thenReturn(false);
|
||||
when(mContext.getPackageManager()).thenReturn(mPm);
|
||||
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mContext.getSystemService(LauncherApps.class)).thenReturn(launcherApps);
|
||||
enableAllDefaultAspectRatioOptions();
|
||||
|
||||
mUtils = new FakeUserAspectRatioManager(mContext, mIPm);
|
||||
mUtils = new FakeUserAspectRatioManager(mContext, mIPm, mActivityTaskManager);
|
||||
|
||||
doReturn(mLauncherActivities).when(launcherApps).getActivityList(anyString(), any());
|
||||
|
||||
@@ -293,7 +298,7 @@ public class UserAspectRatioManagerTest {
|
||||
when(mResources.getIntArray(anyInt())).thenReturn(new int[] {USER_MIN_ASPECT_RATIO_UNSET});
|
||||
when(mResources.getStringArray(anyInt())).thenReturn(new String[] {newOptionName});
|
||||
|
||||
mUtils = new FakeUserAspectRatioManager(mContext, mIPm);
|
||||
mUtils = new FakeUserAspectRatioManager(mContext, mIPm, mActivityTaskManager);
|
||||
|
||||
assertThat(getUserMinAspectRatioEntry(USER_MIN_ASPECT_RATIO_UNSET, mPackageName))
|
||||
.isEqualTo(newOptionName);
|
||||
@@ -305,7 +310,8 @@ public class UserAspectRatioManagerTest {
|
||||
when(mResources.getIntArray(anyInt())).thenReturn(new int[] {USER_MIN_ASPECT_RATIO_4_3});
|
||||
when(mResources.getStringArray(anyInt())).thenReturn(new String[] {"4:3"});
|
||||
|
||||
assertThrows(RuntimeException.class, () -> new FakeUserAspectRatioManager(mContext, mIPm));
|
||||
assertThrows(RuntimeException.class, () -> new FakeUserAspectRatioManager(mContext, mIPm,
|
||||
mActivityTaskManager));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -315,7 +321,8 @@ public class UserAspectRatioManagerTest {
|
||||
USER_MIN_ASPECT_RATIO_4_3});
|
||||
when(mResources.getStringArray(anyInt())).thenReturn(new String[] {"4:3"});
|
||||
|
||||
assertThrows(RuntimeException.class, () -> new FakeUserAspectRatioManager(mContext, mIPm));
|
||||
assertThrows(RuntimeException.class, () -> new FakeUserAspectRatioManager(mContext, mIPm,
|
||||
mActivityTaskManager));
|
||||
}
|
||||
|
||||
private void assertUnsetIsFullscreen() {
|
||||
@@ -347,7 +354,8 @@ public class UserAspectRatioManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserMinAspectRatioEntry_enabledFullscreenOverrideUniRes_returnsFullscreen() {
|
||||
public void testGetUserMinAspectRatioEntry_enabledFullscreenOverrideUniRes_returnsFullscreen()
|
||||
throws RemoteException {
|
||||
setIsOverrideToFullscreenEnabledBecauseUniversalResizeable(true);
|
||||
assertUnsetIsFullscreen();
|
||||
}
|
||||
@@ -359,7 +367,8 @@ public class UserAspectRatioManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserMinAspectRatioEntry_noFullscreenUnivRes_returnsUnchanged() {
|
||||
public void testGetUserMinAspectRatioEntry_noFullscreenUnivRes_returnsUnchanged()
|
||||
throws RemoteException {
|
||||
setIsOverrideToFullscreenEnabledBecauseUniversalResizeable(false);
|
||||
assertUnsetIsAppDefault();
|
||||
}
|
||||
@@ -376,7 +385,7 @@ public class UserAspectRatioManagerTest {
|
||||
|
||||
@Test
|
||||
public void testIsOverrideToFullscreenEnabledUnivRes_returnsTrue()
|
||||
throws PackageManager.NameNotFoundException {
|
||||
throws PackageManager.NameNotFoundException, RemoteException {
|
||||
setIsOverrideToFullscreenEnabledBecauseUniversalResizeable(true);
|
||||
assertTrue(mUtils.isOverrideToFullscreenEnabled(mPackageName, mContext.getUserId()));
|
||||
|
||||
@@ -412,8 +421,11 @@ public class UserAspectRatioManagerTest {
|
||||
.thenReturn(enabled);
|
||||
}
|
||||
|
||||
private void setIsOverrideToFullscreenEnabledBecauseUniversalResizeable(boolean enabled) {
|
||||
mUtils.setUniversalResizeable(enabled);
|
||||
private void setIsOverrideToFullscreenEnabledBecauseUniversalResizeable(boolean enabled)
|
||||
throws RemoteException {
|
||||
when(mIPm.getApplicationInfo(anyString(), anyLong(), anyInt())).thenReturn(
|
||||
new ApplicationInfo());
|
||||
when(mActivityTaskManager.canBeUniversalResizeable(any())).thenReturn(enabled);
|
||||
when(mUtils.hasAspectRatioOption(USER_MIN_ASPECT_RATIO_FULLSCREEN, mPackageName))
|
||||
.thenReturn(enabled);
|
||||
}
|
||||
@@ -476,10 +488,10 @@ public class UserAspectRatioManagerTest {
|
||||
|
||||
private static class FakeUserAspectRatioManager extends UserAspectRatioManager {
|
||||
private boolean mFullscreenCompatChange = false;
|
||||
private boolean mIsUniversalResizeable = false;
|
||||
|
||||
private FakeUserAspectRatioManager(@NonNull Context context, IPackageManager pm) {
|
||||
super(context, pm);
|
||||
private FakeUserAspectRatioManager(@NonNull Context context, IPackageManager pm,
|
||||
ActivityTaskManager mMockActivityTaskManager) {
|
||||
super(context, pm, mMockActivityTaskManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -487,17 +499,8 @@ public class UserAspectRatioManagerTest {
|
||||
return mFullscreenCompatChange;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isUniversalResizeable(String pkgName, int userId) {
|
||||
return mIsUniversalResizeable;
|
||||
}
|
||||
|
||||
void setFullscreenCompatChange(boolean enabled) {
|
||||
mFullscreenCompatChange = enabled;
|
||||
}
|
||||
|
||||
void setUniversalResizeable(boolean enabled) {
|
||||
mIsUniversalResizeable = enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user