Add Extra App Info into Settings App UI.

Bug: b/174956516
Test: Settings -> Apps -> APP -> Extra App Info
Change-Id: Id978fb3569579f54b8399156d52c2ddeceb9bb91
This commit is contained in:
Trevor David Black
2020-12-22 20:09:15 +00:00
parent 18ae34ec90
commit d0d796c90b
11 changed files with 228 additions and 0 deletions

View File

@@ -12805,4 +12805,7 @@
<string name="enable_2g_title">Allow 2G</string> <string name="enable_2g_title">Allow 2G</string>
<!-- Title for toggle if user wants to enable 2G [CHAR LIMIT=NONE] --> <!-- Title for toggle if user wants to enable 2G [CHAR LIMIT=NONE] -->
<string name="enable_2g_summary">Use 2G cellular connections. For emergency calls, 2G is always turned on.</string> <string name="enable_2g_summary">Use 2G cellular connections. For emergency calls, 2G is always turned on.</string>
<!-- Label for extra app info settings for a specific app [CHAR LIMIT=40] -->
<string name="extra_app_info_label" translatable="false"></string>
</resources> </resources>

View File

@@ -80,6 +80,11 @@
android:summary="@string/summary_placeholder" android:summary="@string/summary_placeholder"
settings:controller="com.android.settings.applications.appinfo.AppDataUsagePreferenceController" /> settings:controller="com.android.settings.applications.appinfo.AppDataUsagePreferenceController" />
<Preference
android:key="extra_app_info_settings"
android:title="@string/extra_app_info_label"
settings:controller="com.android.settings.applications.appinfo.ExtraAppInfoPreferenceController" />
<Preference <Preference
android:key="time_spent_in_app" android:key="time_spent_in_app"
android:title="@string/time_spent_in_app_pref_title" android:title="@string/time_spent_in_app_pref_title"

View File

@@ -166,6 +166,9 @@ public class AppInfoDashboardFragment extends DashboardFragment
use(AppStoragePreferenceController.class).setParentFragment(this); use(AppStoragePreferenceController.class).setParentFragment(this);
use(AppVersionPreferenceController.class).setParentFragment(this); use(AppVersionPreferenceController.class).setParentFragment(this);
use(InstantAppDomainsPreferenceController.class).setParentFragment(this); use(InstantAppDomainsPreferenceController.class).setParentFragment(this);
if (FeatureFlagUtils.isEnabled(context, FeatureFlags.SILKY_HOME)) {
use(ExtraAppInfoPreferenceController.class).setPackageName(packageName);
}
final WriteSystemSettingsPreferenceController writeSystemSettings = final WriteSystemSettingsPreferenceController writeSystemSettings =
use(WriteSystemSettingsPreferenceController.class); use(WriteSystemSettingsPreferenceController.class);

View File

@@ -0,0 +1,37 @@
/*
* 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.appinfo;
import android.content.Context;
/**
* Provider for Extra App Info related feature
*/
public interface ExtraAppInfoFeatureProvider {
/** Returns true if the feature is supported. */
boolean isSupported(Context context);
/**
* Launch ExtraAppInfoSettings
*/
void launchExtraAppInfoSettings(Context context);
/**
* Sets the package name
*/
void setPackageName(String packageName);
}

View File

@@ -0,0 +1,40 @@
/*
* 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.appinfo;
import android.content.Context;
/**
* Provider for Extra App Info related feature
*/
public class ExtraAppInfoFeatureProviderImpl implements
ExtraAppInfoFeatureProvider {
@Override
public boolean isSupported(Context context) {
return false;
}
@Override
public void launchExtraAppInfoSettings(Context context) {
return;
}
@Override
public void setPackageName(String packageName) {
return;
}
}

View File

@@ -0,0 +1,61 @@
/*
* 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.appinfo;
import android.content.Context;
import android.text.TextUtils;
import androidx.preference.Preference;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.overlay.FeatureFactory;
/** Contains logic that deals with showing extra app info in app settings. */
public class ExtraAppInfoPreferenceController extends BasePreferenceController {
private final ExtraAppInfoFeatureProvider mExtraAppInfoFeatureProvider;
public ExtraAppInfoPreferenceController(Context context, String key) {
super(context, key);
mExtraAppInfoFeatureProvider =
FeatureFactory.getFactory(context).getExtraAppInfoFeatureProvider();
}
@Override
public int getAvailabilityStatus() {
return mExtraAppInfoFeatureProvider.isSupported(mContext)
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (TextUtils.equals(getPreferenceKey(), preference.getKey())) {
mExtraAppInfoFeatureProvider.launchExtraAppInfoSettings(mContext);
return true;
}
return super.handlePreferenceTreeClick(preference);
}
/**
* Set the local package name
*/
public void setPackageName(String packageName) {
if (mExtraAppInfoFeatureProvider != null) {
mExtraAppInfoFeatureProvider.setPackageName(packageName);
}
}
}

View File

@@ -25,6 +25,7 @@ import androidx.annotation.Nullable;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.accounts.AccountFeatureProvider; import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProvider; import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.applications.appinfo.ExtraAppInfoFeatureProvider;
import com.android.settings.aware.AwareFeatureProvider; import com.android.settings.aware.AwareFeatureProvider;
import com.android.settings.biometrics.face.FaceFeatureProvider; import com.android.settings.biometrics.face.FaceFeatureProvider;
import com.android.settings.bluetooth.BluetoothFeatureProvider; import com.android.settings.bluetooth.BluetoothFeatureProvider;
@@ -149,6 +150,11 @@ public abstract class FeatureFactory {
*/ */
public abstract WifiTrackerLibProvider getWifiTrackerLibProvider(); public abstract WifiTrackerLibProvider getWifiTrackerLibProvider();
/**
* Retrieve implementation for Extra App Info feature.
*/
public abstract ExtraAppInfoFeatureProvider getExtraAppInfoFeatureProvider();
public static final class FactoryNotFoundException extends RuntimeException { public static final class FactoryNotFoundException extends RuntimeException {
public FactoryNotFoundException(Throwable throwable) { public FactoryNotFoundException(Throwable throwable) {
super("Unable to create factory. Did you misconfigure Proguard?", 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.accounts.AccountFeatureProviderImpl;
import com.android.settings.applications.ApplicationFeatureProvider; import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProviderImpl; import com.android.settings.applications.ApplicationFeatureProviderImpl;
import com.android.settings.applications.appinfo.ExtraAppInfoFeatureProvider;
import com.android.settings.applications.appinfo.ExtraAppInfoFeatureProviderImpl;
import com.android.settings.aware.AwareFeatureProvider; import com.android.settings.aware.AwareFeatureProvider;
import com.android.settings.aware.AwareFeatureProviderImpl; import com.android.settings.aware.AwareFeatureProviderImpl;
import com.android.settings.biometrics.face.FaceFeatureProvider; import com.android.settings.biometrics.face.FaceFeatureProvider;
@@ -94,6 +96,7 @@ public class FeatureFactoryImpl extends FeatureFactory {
private AwareFeatureProvider mAwareFeatureProvider; private AwareFeatureProvider mAwareFeatureProvider;
private FaceFeatureProvider mFaceFeatureProvider; private FaceFeatureProvider mFaceFeatureProvider;
private WifiTrackerLibProvider mWifiTrackerLibProvider; private WifiTrackerLibProvider mWifiTrackerLibProvider;
private ExtraAppInfoFeatureProvider mExtraAppInfoFeatureProvider;
@Override @Override
public SupportFeatureProvider getSupportFeatureProvider(Context context) { public SupportFeatureProvider getSupportFeatureProvider(Context context) {
@@ -291,4 +294,12 @@ public class FeatureFactoryImpl extends FeatureFactory {
} }
return mWifiTrackerLibProvider; return mWifiTrackerLibProvider;
} }
@Override
public ExtraAppInfoFeatureProvider getExtraAppInfoFeatureProvider() {
if (mExtraAppInfoFeatureProvider == null) {
mExtraAppInfoFeatureProvider = new ExtraAppInfoFeatureProviderImpl();
}
return mExtraAppInfoFeatureProvider;
}
} }

View File

@@ -0,0 +1,46 @@
/*
* 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.appinfo;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class ExtraAppInfoPreferenceControllerTest {
private Context mContext;
private ExtraAppInfoPreferenceController mController;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mController = new ExtraAppInfoPreferenceController(mContext, "test_key");
}
@Test
public void getAvailabilityStatus_unavailableByDefault() {
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.accounts.AccountFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProvider; import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.applications.appinfo.ExtraAppInfoFeatureProvider;
import com.android.settings.aware.AwareFeatureProvider; import com.android.settings.aware.AwareFeatureProvider;
import com.android.settings.biometrics.face.FaceFeatureProvider; import com.android.settings.biometrics.face.FaceFeatureProvider;
import com.android.settings.bluetooth.BluetoothFeatureProvider; import com.android.settings.bluetooth.BluetoothFeatureProvider;
@@ -79,6 +80,7 @@ public class FakeFeatureFactory extends FeatureFactory {
public ContextualCardFeatureProvider mContextualCardFeatureProvider; public ContextualCardFeatureProvider mContextualCardFeatureProvider;
public WifiTrackerLibProvider wifiTrackerLibProvider; public WifiTrackerLibProvider wifiTrackerLibProvider;
public ExtraAppInfoFeatureProvider extraAppInfoFeatureProvider;
/** /**
* Call this in {@code @Before} method of the test class to use fake factory. * Call this in {@code @Before} method of the test class to use fake factory.
@@ -124,6 +126,7 @@ public class FakeFeatureFactory extends FeatureFactory {
mAwareFeatureProvider = mock(AwareFeatureProvider.class); mAwareFeatureProvider = mock(AwareFeatureProvider.class);
mFaceFeatureProvider = mock(FaceFeatureProvider.class); mFaceFeatureProvider = mock(FaceFeatureProvider.class);
wifiTrackerLibProvider = mock(WifiTrackerLibProvider.class); wifiTrackerLibProvider = mock(WifiTrackerLibProvider.class);
extraAppInfoFeatureProvider = mock(ExtraAppInfoFeatureProvider.class);
} }
@Override @Override
@@ -240,4 +243,9 @@ public class FakeFeatureFactory extends FeatureFactory {
public WifiTrackerLibProvider getWifiTrackerLibProvider() { public WifiTrackerLibProvider getWifiTrackerLibProvider() {
return wifiTrackerLibProvider; return wifiTrackerLibProvider;
} }
@Override
public ExtraAppInfoFeatureProvider getExtraAppInfoFeatureProvider() {
return extraAppInfoFeatureProvider;
}
} }

View File

@@ -21,6 +21,7 @@ import android.content.Context;
import com.android.settings.accounts.AccountFeatureProvider; import com.android.settings.accounts.AccountFeatureProvider;
import com.android.settings.applications.ApplicationFeatureProvider; import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.applications.appinfo.ExtraAppInfoFeatureProvider;
import com.android.settings.aware.AwareFeatureProvider; import com.android.settings.aware.AwareFeatureProvider;
import com.android.settings.biometrics.face.FaceFeatureProvider; import com.android.settings.biometrics.face.FaceFeatureProvider;
import com.android.settings.bluetooth.BluetoothFeatureProvider; import com.android.settings.bluetooth.BluetoothFeatureProvider;
@@ -74,6 +75,7 @@ public class FakeFeatureFactory extends FeatureFactory {
public ContextualCardFeatureProvider mContextualCardFeatureProvider; public ContextualCardFeatureProvider mContextualCardFeatureProvider;
public WifiTrackerLibProvider wifiTrackerLibProvider; public WifiTrackerLibProvider wifiTrackerLibProvider;
public ExtraAppInfoFeatureProvider extraAppInfoFeatureProvider;
/** /**
* Call this in {@code @Before} method of the test class to use fake factory. * Call this in {@code @Before} method of the test class to use fake factory.
@@ -110,6 +112,7 @@ public class FakeFeatureFactory extends FeatureFactory {
mAwareFeatureProvider = mock(AwareFeatureProvider.class); mAwareFeatureProvider = mock(AwareFeatureProvider.class);
mFaceFeatureProvider = mock(FaceFeatureProvider.class); mFaceFeatureProvider = mock(FaceFeatureProvider.class);
wifiTrackerLibProvider = mock(WifiTrackerLibProvider.class); wifiTrackerLibProvider = mock(WifiTrackerLibProvider.class);
extraAppInfoFeatureProvider = mock(ExtraAppInfoFeatureProvider.class);
} }
@Override @Override
@@ -226,4 +229,9 @@ public class FakeFeatureFactory extends FeatureFactory {
public WifiTrackerLibProvider getWifiTrackerLibProvider() { public WifiTrackerLibProvider getWifiTrackerLibProvider() {
return wifiTrackerLibProvider; return wifiTrackerLibProvider;
} }
@Override
public ExtraAppInfoFeatureProvider getExtraAppInfoFeatureProvider() {
return extraAppInfoFeatureProvider;
}
} }