[3/n] Add aspect ratio app info page

Apps > App Info > Advanced > Aspect ratio

Adds link from aspect ratio app list page to app info. Stops activity if
user chooses a different aspect ratio override.

To enable feature:
adb shell device_config put window_manager enable_app_compat_user_aspect_ratio_settings true
adb shell am force-stop com.android.settings

Bug: 287448187
Test: Manual
      All Settings CUJs passed
      atest SettingsRoboTests:UserAspectRatioDetailsTest
      atest SettingsSpaUnitTests:UserAspectRatioAppPreferenceTest
Change-Id: Id47f291459e62267bf15d629c163dde73d96928a
This commit is contained in:
Graciela Wissen Putri
2023-06-26 16:58:33 +00:00
parent c8eb80bcc2
commit 57984f02d5
13 changed files with 735 additions and 22 deletions

View File

@@ -0,0 +1,97 @@
/*
* Copyright (C) 2023 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.settings.applications.appcompat;
import static com.android.settings.applications.appcompat.UserAspectRatioDetails.KEY_PREF_3_2;
import static com.android.settings.applications.appcompat.UserAspectRatioDetails.KEY_PREF_DEFAULT;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.IActivityManager;
import android.content.Context;
import android.os.RemoteException;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.testutils.shadow.ShadowActivityManager;
import com.android.settingslib.widget.SelectorWithWidgetPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
/**
* To run test: atest SettingsRoboTests:UserAspectRatioDetailsTest
*/
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowActivityManager.class})
public class UserAspectRatioDetailsTest {
@Mock
private UserAspectRatioManager mUserAspectRatioManager;
@Mock
private IActivityManager mAm;
private SelectorWithWidgetPreference mRadioButtonPref;
private Context mContext;
private UserAspectRatioDetails mFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
mFragment = spy(new UserAspectRatioDetails());
when(mFragment.getContext()).thenReturn(mContext);
when(mFragment.getAspectRatioManager()).thenReturn(mUserAspectRatioManager);
ShadowActivityManager.setService(mAm);
mRadioButtonPref = new SelectorWithWidgetPreference(mContext);
}
@Test
public void onRadioButtonClicked_prefChange_shouldStopActivity() throws RemoteException {
// Default was already selected
mRadioButtonPref.setKey(KEY_PREF_DEFAULT);
mFragment.onRadioButtonClicked(mRadioButtonPref);
// Preference changed
mRadioButtonPref.setKey(KEY_PREF_3_2);
mFragment.onRadioButtonClicked(mRadioButtonPref);
// Only triggered once when preference change
verify(mAm).stopAppForUser(any(), anyInt());
}
@Test
public void onRadioButtonClicked_prefChange_shouldSetAspectRatio() throws RemoteException {
// Default was already selected
mRadioButtonPref.setKey(KEY_PREF_DEFAULT);
mFragment.onRadioButtonClicked(mRadioButtonPref);
// Preference changed
mRadioButtonPref.setKey(KEY_PREF_3_2);
mFragment.onRadioButtonClicked(mRadioButtonPref);
// Only triggered once when preference changes
verify(mUserAspectRatioManager).setUserMinAspectRatio(
any(), anyInt(), anyInt());
}
}