Snap for 7834211 from 57919fbcfb to sc-v2-release
Change-Id: I9f59df3e909248fc833a910cfa5a3d2e17f83b9d
This commit is contained in:
@@ -42,15 +42,7 @@
|
|||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="install_credentials"
|
android:key="install_credentials"
|
||||||
android:title="@string/wifi_install_credentials">
|
android:title="@string/wifi_install_credentials"/>
|
||||||
<intent
|
|
||||||
android:action="android.credentials.INSTALL"
|
|
||||||
android:targetPackage="com.android.certinstaller"
|
|
||||||
android:targetClass="com.android.certinstaller.CertInstallerMain">
|
|
||||||
<!-- Same value as CERTIFICATE_USAGE_WIFI in keystore/java/android/security/Credentials.java -->
|
|
||||||
<extra android:name="certificate_install_usage" android:value="wifi"/>
|
|
||||||
</intent>
|
|
||||||
</Preference>
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="wifi_direct"
|
android:key="wifi_direct"
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ public class SettingsActivity extends SettingsBaseActivity
|
|||||||
getMetaData();
|
getMetaData();
|
||||||
final Intent intent = getIntent();
|
final Intent intent = getIntent();
|
||||||
if (launchHomepageForTwoPaneDeepLink(intent)) {
|
if (launchHomepageForTwoPaneDeepLink(intent)) {
|
||||||
finish();
|
finishAndRemoveTask();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -361,8 +361,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
|||||||
final String stateString;
|
final String stateString;
|
||||||
final String footerString;
|
final String footerString;
|
||||||
|
|
||||||
if (!mBatteryOptimizeUtils.isValidPackageName()
|
if (!mBatteryOptimizeUtils.isValidPackageName()) {
|
||||||
|| mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()) {
|
|
||||||
// Present optimized only string when the package name is invalid or
|
// Present optimized only string when the package name is invalid or
|
||||||
// it's in allow list not idle app.
|
// it's in allow list not idle app.
|
||||||
stateString = context.getString(R.string.manager_battery_usage_optimized_only);
|
stateString = context.getString(R.string.manager_battery_usage_optimized_only);
|
||||||
|
|||||||
@@ -89,8 +89,16 @@ public class BatteryOptimizeUtils {
|
|||||||
return getAppOptimizationMode(mMode, mAllowListed);
|
return getAppOptimizationMode(mMode, mAllowListed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the {@link OptimizationMode} for associated app. */
|
|
||||||
public void setAppOptimizationMode(@OptimizationMode int mode) {
|
public void setAppOptimizationMode(@OptimizationMode int mode) {
|
||||||
|
try {
|
||||||
|
setAppUsageStateInternal(mode);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "setAppUsageState() is failed for " + mPackageName, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the {@link OptimizationMode} for associated app. */
|
||||||
|
public void setAppUsageStateInternal(@OptimizationMode int mode) {
|
||||||
if (getAppOptimizationMode(mMode, mAllowListed) == mode) {
|
if (getAppOptimizationMode(mMode, mAllowListed) == mode) {
|
||||||
Log.w(TAG, "set the same optimization mode for: " + mPackageName);
|
Log.w(TAG, "set the same optimization mode for: " + mPackageName);
|
||||||
return;
|
return;
|
||||||
@@ -130,13 +138,6 @@ public class BatteryOptimizeUtils {
|
|||||||
|| mPowerAllowListBackend.isDefaultActiveApp(mPackageName);
|
|| mPowerAllowListBackend.isDefaultActiveApp(mPackageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return {@code true} if this package is in allow list except idle app.
|
|
||||||
*/
|
|
||||||
public boolean isAllowlistedExceptIdleApp() {
|
|
||||||
return mPowerAllowListBackend.isAllowlistedExceptIdle(mPackageName);
|
|
||||||
}
|
|
||||||
|
|
||||||
String getPackageName() {
|
String getPackageName() {
|
||||||
return mPackageName == null ? UNKNOWN_PACKAGE : mPackageName;
|
return mPackageName == null ? UNKNOWN_PACKAGE : mPackageName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,10 +57,6 @@ public class OptimizedPreferenceController extends AbstractPreferenceController
|
|||||||
Log.d(TAG, "is system or default app, disable pref");
|
Log.d(TAG, "is system or default app, disable pref");
|
||||||
((RadioButtonPreference) preference).setChecked(false);
|
((RadioButtonPreference) preference).setChecked(false);
|
||||||
preference.setEnabled(false);
|
preference.setEnabled(false);
|
||||||
} else if (mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()) {
|
|
||||||
Log.d(TAG, "in allow list not idle app, optimized states only");
|
|
||||||
preference.setEnabled(true);
|
|
||||||
((RadioButtonPreference) preference).setChecked(true);
|
|
||||||
} else if (mBatteryOptimizeUtils.getAppOptimizationMode()
|
} else if (mBatteryOptimizeUtils.getAppOptimizationMode()
|
||||||
== BatteryOptimizeUtils.MODE_OPTIMIZED) {
|
== BatteryOptimizeUtils.MODE_OPTIMIZED) {
|
||||||
Log.d(TAG, "is optimized states");
|
Log.d(TAG, "is optimized states");
|
||||||
|
|||||||
@@ -55,9 +55,6 @@ public class RestrictedPreferenceController extends AbstractPreferenceController
|
|||||||
Log.d(TAG, "is system or default app, disable pref");
|
Log.d(TAG, "is system or default app, disable pref");
|
||||||
((RadioButtonPreference) preference).setChecked(false);
|
((RadioButtonPreference) preference).setChecked(false);
|
||||||
preference.setEnabled(false);
|
preference.setEnabled(false);
|
||||||
} else if (mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()) {
|
|
||||||
Log.d(TAG, "in allow list not idle app, disable perf");
|
|
||||||
preference.setEnabled(false);
|
|
||||||
} else if (mBatteryOptimizeUtils.getAppOptimizationMode()
|
} else if (mBatteryOptimizeUtils.getAppOptimizationMode()
|
||||||
== BatteryOptimizeUtils.MODE_RESTRICTED) {
|
== BatteryOptimizeUtils.MODE_RESTRICTED) {
|
||||||
Log.d(TAG, "is restricted states");
|
Log.d(TAG, "is restricted states");
|
||||||
|
|||||||
@@ -53,9 +53,6 @@ public class UnrestrictedPreferenceController extends AbstractPreferenceControll
|
|||||||
if (mBatteryOptimizeUtils.isSystemOrDefaultApp()) {
|
if (mBatteryOptimizeUtils.isSystemOrDefaultApp()) {
|
||||||
Log.d(TAG, "is system or default app, unrestricted states only");
|
Log.d(TAG, "is system or default app, unrestricted states only");
|
||||||
((RadioButtonPreference) preference).setChecked(true);
|
((RadioButtonPreference) preference).setChecked(true);
|
||||||
} else if (mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()) {
|
|
||||||
Log.d(TAG, "in allow list not idle app, disable perf");
|
|
||||||
preference.setEnabled(false);
|
|
||||||
} else if (mBatteryOptimizeUtils.getAppOptimizationMode()
|
} else if (mBatteryOptimizeUtils.getAppOptimizationMode()
|
||||||
== BatteryOptimizeUtils.MODE_UNRESTRICTED) {
|
== BatteryOptimizeUtils.MODE_UNRESTRICTED) {
|
||||||
Log.d(TAG, "is unrestricted states");
|
Log.d(TAG, "is unrestricted states");
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import android.graphics.Paint;
|
|||||||
import android.graphics.drawable.ShapeDrawable;
|
import android.graphics.drawable.ShapeDrawable;
|
||||||
import android.graphics.drawable.shapes.OvalShape;
|
import android.graphics.drawable.shapes.OvalShape;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.telephony.ServiceState;
|
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
@@ -52,7 +51,6 @@ import com.android.settingslib.DeviceInfoUtils;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -180,8 +178,7 @@ public class RenameMobileNetworkDialogFragment extends InstrumentedDialogFragmen
|
|||||||
|
|
||||||
final TextView operatorName = view.findViewById(R.id.operator_name_value);
|
final TextView operatorName = view.findViewById(R.id.operator_name_value);
|
||||||
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
|
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
|
||||||
final ServiceState serviceState = mTelephonyManager.getServiceState();
|
operatorName.setText(info.getCarrierName());
|
||||||
operatorName.setText(serviceState == null ? "" : serviceState.getOperatorAlphaLong());
|
|
||||||
|
|
||||||
final TextView phoneTitle = view.findViewById(R.id.number_label);
|
final TextView phoneTitle = view.findViewById(R.id.number_label);
|
||||||
phoneTitle.setVisibility(info.isOpportunistic() ? View.GONE : View.VISIBLE);
|
phoneTitle.setVisibility(info.isOpportunistic() ? View.GONE : View.VISIBLE);
|
||||||
|
|||||||
@@ -18,11 +18,16 @@ package com.android.settings.wifi;
|
|||||||
import static android.content.Context.WIFI_SERVICE;
|
import static android.content.Context.WIFI_SERVICE;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.FeatureFlagUtils;
|
import android.util.FeatureFlagUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
@@ -38,10 +43,17 @@ import java.util.List;
|
|||||||
public class ConfigureWifiSettings extends DashboardFragment {
|
public class ConfigureWifiSettings extends DashboardFragment {
|
||||||
|
|
||||||
private static final String TAG = "ConfigureWifiSettings";
|
private static final String TAG = "ConfigureWifiSettings";
|
||||||
|
private static final String KEY_INSTALL_CREDENTIALS = "install_credentials";
|
||||||
|
private static final String ACTION_INSTALL_CERTS = "android.credentials.INSTALL";
|
||||||
|
private static final String PACKAGE_INSTALL_CERTS = "com.android.certinstaller";
|
||||||
|
private static final String CLASS_INSTALL_CERTS = "com.android.certinstaller.CertInstallerMain";
|
||||||
|
private static final String KEY_INSTALL_CERTIFICATE = "certificate_install_usage";
|
||||||
|
private static final String INSTALL_CERTIFICATE_VALUE = "wifi";
|
||||||
|
|
||||||
public static final int WIFI_WAKEUP_REQUEST_CODE = 600;
|
public static final int WIFI_WAKEUP_REQUEST_CODE = 600;
|
||||||
|
|
||||||
private WifiWakeupPreferenceController mWifiWakeupPreferenceController;
|
private WifiWakeupPreferenceController mWifiWakeupPreferenceController;
|
||||||
|
private Preference mCertinstallerPreference;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
@@ -49,6 +61,22 @@ public class ConfigureWifiSettings extends DashboardFragment {
|
|||||||
if (FeatureFlagUtils.isEnabled(getContext(), FeatureFlagUtils.SETTINGS_PROVIDER_MODEL)) {
|
if (FeatureFlagUtils.isEnabled(getContext(), FeatureFlagUtils.SETTINGS_PROVIDER_MODEL)) {
|
||||||
getActivity().setTitle(R.string.network_and_internet_preferences_title);
|
getActivity().setTitle(R.string.network_and_internet_preferences_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mCertinstallerPreference = findPreference(KEY_INSTALL_CREDENTIALS);
|
||||||
|
if (mCertinstallerPreference != null) {
|
||||||
|
mCertinstallerPreference.setOnPreferenceClickListener(preference -> {
|
||||||
|
Intent intent = new Intent(ACTION_INSTALL_CERTS);
|
||||||
|
intent.setFlags(
|
||||||
|
Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.setComponent(
|
||||||
|
new ComponentName(PACKAGE_INSTALL_CERTS, CLASS_INSTALL_CERTS));
|
||||||
|
intent.putExtra(KEY_INSTALL_CERTIFICATE, INSTALL_CERTIFICATE_VALUE);
|
||||||
|
getContext().startActivity(intent);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "Can not find the preference.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -745,16 +745,6 @@ public class AdvancedPowerUsageDetailTest {
|
|||||||
.isEqualTo("This app requires optimized battery usage.");
|
.isEqualTo("This app requires optimized battery usage.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInitPreferenceForTriState_isAllowlistedExceptIdleApp_hasCorrectString() {
|
|
||||||
when(mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).thenReturn(true);
|
|
||||||
|
|
||||||
mFragment.initPreferenceForTriState(mContext);
|
|
||||||
|
|
||||||
assertThat(mFooterPreference.getTitle().toString())
|
|
||||||
.isEqualTo("This app requires optimized battery usage.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInitPreferenceForTriState_isSystemOrDefaultApp_hasCorrectString() {
|
public void testInitPreferenceForTriState_isSystemOrDefaultApp_hasCorrectString() {
|
||||||
when(mBatteryOptimizeUtils.isValidPackageName()).thenReturn(true);
|
when(mBatteryOptimizeUtils.isValidPackageName()).thenReturn(true);
|
||||||
|
|||||||
@@ -124,18 +124,6 @@ public class BatteryOptimizeUtilsTest {
|
|||||||
assertThat(mBatteryOptimizeUtils.isValidPackageName()).isTrue();
|
assertThat(mBatteryOptimizeUtils.isValidPackageName()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsAllowlistedExpectIdle_isAllowlistedExceptIdle_returnTrue() {
|
|
||||||
when(mMockBackend.isAllowlistedExceptIdle(anyString())).thenReturn(true);
|
|
||||||
|
|
||||||
assertThat(mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsAllowlistedExpectIdle_notAllowlistedExpectIdle_returnFalse() {
|
|
||||||
assertThat(mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetAppOptimizationMode_Restricted_verifyAction() {
|
public void testSetAppOptimizationMode_Restricted_verifyAction() {
|
||||||
// Sets the current mode as MODE_UNRESTRICTED.
|
// Sets the current mode as MODE_UNRESTRICTED.
|
||||||
|
|||||||
@@ -93,16 +93,6 @@ public class OptimizedPreferenceControllerTest {
|
|||||||
assertThat(mPreference.isChecked()).isFalse();
|
assertThat(mPreference.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateState_isAllowlistedExceptIdleApp_prefEnabled() {
|
|
||||||
when(mockBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).thenReturn(true);
|
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
|
|
||||||
assertThat(mPreference.isEnabled()).isTrue();
|
|
||||||
assertThat(mPreference.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandlePreferenceTreeClick_samePrefKey_verifyAction() {
|
public void testHandlePreferenceTreeClick_samePrefKey_verifyAction() {
|
||||||
mPreference.setKey(mController.KEY_OPTIMIZED_PREF);
|
mPreference.setKey(mController.KEY_OPTIMIZED_PREF);
|
||||||
|
|||||||
@@ -101,16 +101,6 @@ public class RestrictedPreferenceControllerTest {
|
|||||||
assertThat(mPreference.isChecked()).isFalse();
|
assertThat(mPreference.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateState_isAllowlistedExceptIdleApp_prefDisabled() {
|
|
||||||
when(mockBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).thenReturn(true);
|
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
|
|
||||||
assertThat(mPreference.isChecked()).isFalse();
|
|
||||||
assertThat(mPreference.isEnabled()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandlePreferenceTreeClick_samePrefKey_verifyAction() {
|
public void testHandlePreferenceTreeClick_samePrefKey_verifyAction() {
|
||||||
mPreference.setKey(mController.KEY_RESTRICTED_PREF);
|
mPreference.setKey(mController.KEY_RESTRICTED_PREF);
|
||||||
|
|||||||
@@ -101,16 +101,6 @@ public class UnrestrictedPreferenceControllerTest {
|
|||||||
assertThat(mPreference.isChecked()).isFalse();
|
assertThat(mPreference.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateState_isAllowlistedExceptIdleApp_prefDisabled() {
|
|
||||||
when(mockBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).thenReturn(true);
|
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
|
|
||||||
assertThat(mPreference.isChecked()).isFalse();
|
|
||||||
assertThat(mPreference.isEnabled()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandlePreferenceTreeClick_samePrefKey_verifyAction() {
|
public void testHandlePreferenceTreeClick_samePrefKey_verifyAction() {
|
||||||
mPreference.setKey(mController.KEY_UNRESTRICTED_PREF);
|
mPreference.setKey(mController.KEY_UNRESTRICTED_PREF);
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import static org.mockito.Mockito.when;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.telephony.ServiceState;
|
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
@@ -73,8 +72,6 @@ public class RenameMobileNetworkDialogFragmentTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private TelephonyManager mTelephonyMgr;
|
private TelephonyManager mTelephonyMgr;
|
||||||
@Mock
|
@Mock
|
||||||
private ServiceState mServiceState;
|
|
||||||
@Mock
|
|
||||||
private SubscriptionManager mSubscriptionMgr;
|
private SubscriptionManager mSubscriptionMgr;
|
||||||
@Mock
|
@Mock
|
||||||
private SubscriptionInfo mSubscriptionInfo;
|
private SubscriptionInfo mSubscriptionInfo;
|
||||||
@@ -95,11 +92,9 @@ public class RenameMobileNetworkDialogFragmentTest {
|
|||||||
stm.setTelephonyManagerForSubscriptionId(mSubscriptionId, mTelephonyMgr);
|
stm.setTelephonyManagerForSubscriptionId(mSubscriptionId, mTelephonyMgr);
|
||||||
when(mTelephonyMgr.createForSubscriptionId(anyInt())).thenReturn(mTelephonyMgr);
|
when(mTelephonyMgr.createForSubscriptionId(anyInt())).thenReturn(mTelephonyMgr);
|
||||||
|
|
||||||
when(mTelephonyMgr.getServiceState()).thenReturn(mServiceState);
|
|
||||||
when(mServiceState.getOperatorAlphaLong()).thenReturn("fake carrier name");
|
|
||||||
|
|
||||||
when(mSubscriptionInfo.getSubscriptionId()).thenReturn(mSubscriptionId);
|
when(mSubscriptionInfo.getSubscriptionId()).thenReturn(mSubscriptionId);
|
||||||
when(mSubscriptionInfo.getDisplayName()).thenReturn("test");
|
when(mSubscriptionInfo.getDisplayName()).thenReturn("test");
|
||||||
|
when(mSubscriptionInfo.getCarrierName()).thenReturn("fake carrier name");
|
||||||
when(mSubscriptionMgr.setDisplayName(any(), anyInt(), anyInt())).thenReturn(0);
|
when(mSubscriptionMgr.setDisplayName(any(), anyInt(), anyInt())).thenReturn(0);
|
||||||
|
|
||||||
mActivity = spy(Robolectric.buildActivity(FragmentActivity.class).setup().get());
|
mActivity = spy(Robolectric.buildActivity(FragmentActivity.class).setup().get());
|
||||||
|
|||||||
Reference in New Issue
Block a user