Merge "Add Game settings support." into sc-dev

This commit is contained in:
Peiyong Lin
2021-05-19 05:42:14 +00:00
committed by Android (Google) Code Review
10 changed files with 240 additions and 0 deletions

View File

@@ -13297,4 +13297,9 @@
<string name="mic_toggle_title">Microphone access</string>
<!-- Describes what is affected by the camera or mic toggle [CHAR LIMIT=NONE] -->
<string name="sensor_toggle_description">For all apps and services</string>
<!-- Title for Game settings entry. [CHAR_LIMIT=NONE] -->
<string name="game_settings_title">Game settings</string>
<!-- Summary for Game settings entry. [CHAR_LIMIT=NONE] -->
<string name="game_settings_summary">Turn on Game Dashboard shortcut, etc</string>
</resources>

View File

@@ -62,6 +62,14 @@
<intent android:action="android.settings.MANAGE_DEFAULT_APPS_SETTINGS"/>
</Preference>
<Preference
android:key="game_settings"
android:title="@string/game_settings_title"
android:summary="@string/game_settings_summary"
android:order="-995"
settings:controller="com.android.settings.applications.GameSettingsPreferenceController">
</Preference>
<PreferenceCategory
android:key="dashboard_tile_placeholder"
android:order="10"/>

View File

@@ -0,0 +1,34 @@
/*
* Copyright (C) 2021 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;
import android.content.Context;
/**
* Provider for Game Settings related feature.
*/
public interface GameSettingsFeatureProvider {
/**
* Returns true if the feature is supported.
*/
boolean isSupported(Context context);
/**
* Launch GameSettings
*/
void launchGameSettings(Context context);
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (C) 2021 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;
import android.content.Context;
/**
* Provider implementation for Game Settings related features.
*/
public class GameSettingsFeatureProviderImpl implements
GameSettingsFeatureProvider {
@Override
public boolean isSupported(Context context) {
return false;
}
@Override
public void launchGameSettings(Context context) {
return;
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (C) 2021 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;
import android.content.Context;
import android.text.TextUtils;
import androidx.preference.Preference;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.overlay.FeatureFactory;
/** Contains logic that deals with showing Game Settings in app settings. */
public class GameSettingsPreferenceController extends BasePreferenceController {
@VisibleForTesting
final GameSettingsFeatureProvider mGameSettingsFeatureProvider;
public GameSettingsPreferenceController(Context context, String key) {
super(context, key);
mGameSettingsFeatureProvider =
FeatureFactory.getFactory(context).getGameSettingsFeatureProvider();
}
GameSettingsPreferenceController(Context context, String key,
GameSettingsFeatureProvider gameSettingsFeatureProvider) {
super(context, key);
mGameSettingsFeatureProvider = gameSettingsFeatureProvider;
}
@Override
public int getAvailabilityStatus() {
return mGameSettingsFeatureProvider.isSupported(mContext)
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (TextUtils.equals(getPreferenceKey(), preference.getKey())) {
mGameSettingsFeatureProvider.launchGameSettings(mContext);
return true;
}
return super.handlePreferenceTreeClick(preference);
}
}

View File

@@ -25,6 +25,7 @@ import androidx.annotation.Nullable;
import com.android.settings.R;
import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.applications.GameSettingsFeatureProvider;
import com.android.settings.applications.appinfo.ExtraAppInfoFeatureProvider;
import com.android.settings.aware.AwareFeatureProvider;
import com.android.settings.biometrics.face.FaceFeatureProvider;
@@ -168,6 +169,11 @@ public abstract class FeatureFactory {
*/
public abstract SecuritySettingsFeatureProvider getSecuritySettingsFeatureProvider();
/**
* Retrieve implementation for Game Settings feature.
*/
public abstract GameSettingsFeatureProvider getGameSettingsFeatureProvider();
public static final class FactoryNotFoundException extends RuntimeException {
public FactoryNotFoundException(Throwable throwable) {
super("Unable to create factory. Did you misconfigure Proguard?", throwable);

View File

@@ -29,6 +29,8 @@ import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.accounts.AccountFeatureProviderImpl;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProviderImpl;
import com.android.settings.applications.GameSettingsFeatureProvider;
import com.android.settings.applications.GameSettingsFeatureProviderImpl;
import com.android.settings.applications.appinfo.ExtraAppInfoFeatureProvider;
import com.android.settings.applications.appinfo.ExtraAppInfoFeatureProviderImpl;
import com.android.settings.aware.AwareFeatureProvider;
@@ -103,6 +105,7 @@ public class FeatureFactoryImpl extends FeatureFactory {
private WifiTrackerLibProvider mWifiTrackerLibProvider;
private ExtraAppInfoFeatureProvider mExtraAppInfoFeatureProvider;
private SecuritySettingsFeatureProvider mSecuritySettingsFeatureProvider;
private GameSettingsFeatureProvider mGameSettingsFeatureProvider;
@Override
public SupportFeatureProvider getSupportFeatureProvider(Context context) {
@@ -324,4 +327,12 @@ public class FeatureFactoryImpl extends FeatureFactory {
}
return mSecuritySettingsFeatureProvider;
}
@Override
public GameSettingsFeatureProvider getGameSettingsFeatureProvider() {
if (mGameSettingsFeatureProvider == null) {
mGameSettingsFeatureProvider = new GameSettingsFeatureProviderImpl();
}
return mGameSettingsFeatureProvider;
}
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2021 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;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class GameSettingsPreferenceControllerTest {
private GameSettingsPreferenceController mController;
private GameSettingsFeatureProvider mProvider;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mProvider = FakeFeatureFactory.setupForTest().getGameSettingsFeatureProvider();
mController = new GameSettingsPreferenceController(mContext, "test_key", mProvider);
}
@Test
public void getAvailabilityStatus_GameSettingsFeatureEnabled_shouldReturnAVAILABLE() {
when(mProvider.isSupported(mContext)).thenReturn(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
public void getAvailabilityStatus_GameSettingsFeatureDisabled_shouldReturnUNSUPPORTED_ON_DEVICE() {
when(mProvider.isSupported(mContext)).thenReturn(false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
}

View File

@@ -23,6 +23,7 @@ import android.content.Context;
import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.applications.GameSettingsFeatureProvider;
import com.android.settings.applications.appinfo.ExtraAppInfoFeatureProvider;
import com.android.settings.aware.AwareFeatureProvider;
import com.android.settings.biometrics.face.FaceFeatureProvider;
@@ -85,6 +86,7 @@ public class FakeFeatureFactory extends FeatureFactory {
public WifiTrackerLibProvider wifiTrackerLibProvider;
public ExtraAppInfoFeatureProvider extraAppInfoFeatureProvider;
public SecuritySettingsFeatureProvider securitySettingsFeatureProvider;
public GameSettingsFeatureProvider gameSettingsFeatureProvider;
/**
* Call this in {@code @Before} method of the test class to use fake factory.
@@ -133,6 +135,7 @@ public class FakeFeatureFactory extends FeatureFactory {
wifiTrackerLibProvider = mock(WifiTrackerLibProvider.class);
extraAppInfoFeatureProvider = mock(ExtraAppInfoFeatureProvider.class);
securitySettingsFeatureProvider = mock(SecuritySettingsFeatureProvider.class);
gameSettingsFeatureProvider = mock(GameSettingsFeatureProvider.class);
}
@Override
@@ -264,4 +267,9 @@ public class FakeFeatureFactory extends FeatureFactory {
public SecuritySettingsFeatureProvider getSecuritySettingsFeatureProvider() {
return securitySettingsFeatureProvider;
}
@Override
public GameSettingsFeatureProvider getGameSettingsFeatureProvider() {
return gameSettingsFeatureProvider;
}
}

View File

@@ -21,6 +21,7 @@ import android.content.Context;
import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.applications.GameSettingsFeatureProvider;
import com.android.settings.applications.appinfo.ExtraAppInfoFeatureProvider;
import com.android.settings.aware.AwareFeatureProvider;
import com.android.settings.biometrics.face.FaceFeatureProvider;
@@ -80,6 +81,7 @@ public class FakeFeatureFactory extends FeatureFactory {
public WifiTrackerLibProvider wifiTrackerLibProvider;
public ExtraAppInfoFeatureProvider extraAppInfoFeatureProvider;
public SecuritySettingsFeatureProvider securitySettingsFeatureProvider;
public GameSettingsFeatureProvider gameSettingsFeatureProvider;
/**
* Call this in {@code @Before} method of the test class to use fake factory.
@@ -119,6 +121,7 @@ public class FakeFeatureFactory extends FeatureFactory {
wifiTrackerLibProvider = mock(WifiTrackerLibProvider.class);
extraAppInfoFeatureProvider = mock(ExtraAppInfoFeatureProvider.class);
securitySettingsFeatureProvider = mock(SecuritySettingsFeatureProvider.class);
gameSettingsFeatureProvider = mock(GameSettingsFeatureProvider.class);
}
@Override
@@ -250,4 +253,9 @@ public class FakeFeatureFactory extends FeatureFactory {
public SecuritySettingsFeatureProvider getSecuritySettingsFeatureProvider() {
return securitySettingsFeatureProvider;
}
@Override
public GameSettingsFeatureProvider getGameSettingsFeatureProvider() {
return gameSettingsFeatureProvider;
}
}