Snap for 6554163 from fd1815af38 to mainline-release

Change-Id: I3a294cd5b5fac6f71357c470631b044d066ff1ab
This commit is contained in:
android-build-team Robot
2020-06-03 07:09:19 +00:00
18 changed files with 607 additions and 83 deletions

View File

@@ -12094,4 +12094,9 @@
<!-- Developer settings: app freezer title [CHAR LIMIT=50]-->
<string name="cached_apps_freezer">Suspend execution for cached apps</string>
<!-- Title for allowing screen overlays on Settings app. [CHAR LIMIT=50]-->
<string name="overlay_settings_title">Allow screen overlays on Settings</string>
<!-- Summary for allowing screen overlays on Settings app. [CHAR LIMIT=NONE]-->
<string name="overlay_settings_summary">Allow apps that can display over other apps to overlay Settings screens</string>
</resources>

View File

@@ -251,6 +251,11 @@
android:title="@string/show_refresh_rate"
android:summary="@string/show_refresh_rate_summary" />
<SwitchPreference
android:key="overlay_settings"
android:title="@string/overlay_settings_title"
android:summary="@string/overlay_settings_summary" />
</PreferenceCategory>
<PreferenceCategory

View File

@@ -87,6 +87,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
private static final String PIN_DIALOG = "sim_pin";
private static final String PIN_TOGGLE = "sim_toggle";
// Keys in icicle
private static final String DIALOG_SUB_ID = "dialogSubId";
private static final String DIALOG_STATE = "dialogState";
private static final String DIALOG_PIN = "dialogPin";
private static final String DIALOG_ERROR = "dialogError";
@@ -127,7 +128,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
// @see android.widget.Toast$TN
private static final long LONG_DURATION_TIMEOUT = 7000;
private int mSlotId;
private int mSlotId = -1;
private int mSubId;
private TelephonyManager mTelephonyManager;
@@ -155,7 +156,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
// For top-level settings screen to query
private boolean isIccLockEnabled() {
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
return mTelephonyManager.isIccLockEnabled();
}
@@ -187,27 +188,13 @@ public class IccLockSettings extends SettingsPreferenceFragment
mPinDialog = (EditPinPreference) findPreference(PIN_DIALOG);
mPinToggle = (SwitchPreference) findPreference(PIN_TOGGLE);
if (savedInstanceState != null && savedInstanceState.containsKey(DIALOG_STATE)) {
mDialogState = savedInstanceState.getInt(DIALOG_STATE);
mPin = savedInstanceState.getString(DIALOG_PIN);
mError = savedInstanceState.getString(DIALOG_ERROR);
mToState = savedInstanceState.getBoolean(ENABLE_TO_STATE);
// Restore inputted PIN code
switch (mDialogState) {
case ICC_NEW_MODE:
mOldPin = savedInstanceState.getString(OLD_PINCODE);
break;
case ICC_REENTER_MODE:
mOldPin = savedInstanceState.getString(OLD_PINCODE);
mNewPin = savedInstanceState.getString(NEW_PINCODE);
break;
case ICC_LOCK_MODE:
case ICC_OLD_MODE:
default:
break;
if (savedInstanceState != null) {
if (savedInstanceState.containsKey(DIALOG_STATE)
&& restoreDialogStates(savedInstanceState)) {
Log.d(TAG, "onCreate: restore dialog for slotId=" + mSlotId + ", subId=" + mSubId);
} else if (savedInstanceState.containsKey(CURRENT_TAB)
&& restoreTabFocus(savedInstanceState)) {
Log.d(TAG, "onCreate: restore focus on slotId=" + mSlotId + ", subId=" + mSubId);
}
}
@@ -219,29 +206,75 @@ public class IccLockSettings extends SettingsPreferenceFragment
mRes = getResources();
}
private boolean restoreDialogStates(Bundle savedInstanceState) {
final SubscriptionInfo subInfo = mProxySubscriptionMgr
.getActiveSubscriptionInfo(savedInstanceState.getInt(DIALOG_SUB_ID));
if (subInfo == null) {
return false;
}
final SubscriptionInfo visibleSubInfo = getVisibleSubscriptionInfoForSimSlotIndex(
subInfo.getSimSlotIndex());
if (visibleSubInfo == null) {
return false;
}
if (visibleSubInfo.getSubscriptionId() != subInfo.getSubscriptionId()) {
return false;
}
mSlotId = subInfo.getSimSlotIndex();
mSubId = subInfo.getSubscriptionId();
mDialogState = savedInstanceState.getInt(DIALOG_STATE);
mPin = savedInstanceState.getString(DIALOG_PIN);
mError = savedInstanceState.getString(DIALOG_ERROR);
mToState = savedInstanceState.getBoolean(ENABLE_TO_STATE);
// Restore inputted PIN code
switch (mDialogState) {
case ICC_NEW_MODE:
mOldPin = savedInstanceState.getString(OLD_PINCODE);
break;
case ICC_REENTER_MODE:
mOldPin = savedInstanceState.getString(OLD_PINCODE);
mNewPin = savedInstanceState.getString(NEW_PINCODE);
break;
}
return true;
}
private boolean restoreTabFocus(Bundle savedInstanceState) {
int slotId = 0;
try {
slotId = Integer.parseInt(savedInstanceState.getString(CURRENT_TAB));
} catch (NumberFormatException exception) {
return false;
}
final SubscriptionInfo subInfo = getVisibleSubscriptionInfoForSimSlotIndex(slotId);
if (subInfo == null) {
return false;
}
mSlotId = subInfo.getSimSlotIndex();
mSubId = subInfo.getSubscriptionId();
if (mTabHost != null) {
mTabHost.setCurrentTabByTag(getTagForSlotId(mSlotId));
}
return true;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final int numSims = mProxySubscriptionMgr.getActiveSubscriptionInfoCountMax();
final List<SubscriptionInfo> subInfoList =
mProxySubscriptionMgr.getActiveSubscriptionsInfo();
mSlotId = 0;
final List<SubscriptionInfo> componenterList = new ArrayList<>();
for (int i = 0; i < numSims; ++i) {
final SubscriptionInfo subInfo =
getActiveSubscriptionInfoForSimSlotIndex(subInfoList, i);
final SubscriptionInfo subInfo = getVisibleSubscriptionInfoForSimSlotIndex(i);
if (subInfo != null) {
final CarrierConfigManager carrierConfigManager = getContext().getSystemService(
CarrierConfigManager.class);
final PersistableBundle bundle = carrierConfigManager.getConfigForSubId(
subInfo.getSubscriptionId());
if (bundle != null
&& !bundle.getBoolean(CarrierConfigManager
.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
componenterList.add(subInfo);
}
componenterList.add(subInfo);
}
}
@@ -250,6 +283,12 @@ public class IccLockSettings extends SettingsPreferenceFragment
return super.onCreateView(inflater, container, savedInstanceState);
}
if (mSlotId < 0) {
mSlotId = componenterList.get(0).getSimSlotIndex();
mSubId = componenterList.get(0).getSubscriptionId();
Log.d(TAG, "onCreateView: default slotId=" + mSlotId + ", subId=" + mSubId);
}
if (componenterList.size() > 1) {
final View view = inflater.inflate(R.layout.icc_lock_tabs, container, false);
final ViewGroup prefs_container = (ViewGroup) view.findViewById(R.id.prefs_container);
@@ -262,25 +301,21 @@ public class IccLockSettings extends SettingsPreferenceFragment
mListView = (ListView) view.findViewById(android.R.id.list);
mTabHost.setup();
mTabHost.setOnTabChangedListener(mTabListener);
mTabHost.clearAllTabs();
for (SubscriptionInfo subInfo : componenterList) {
int slot = subInfo.getSimSlotIndex();
mTabHost.addTab(buildTabSpec(String.valueOf(slot),
final int slot = subInfo.getSimSlotIndex();
final String tag = getTagForSlotId(slot);
mTabHost.addTab(buildTabSpec(tag,
String.valueOf(subInfo == null
? getContext().getString(R.string.sim_editor_title, slot + 1)
: subInfo.getDisplayName())));
}
mSubId = componenterList.get(0).getSubscriptionId();
if (savedInstanceState != null && savedInstanceState.containsKey(CURRENT_TAB)) {
mTabHost.setCurrentTabByTag(savedInstanceState.getString(CURRENT_TAB));
}
mTabHost.setCurrentTabByTag(getTagForSlotId(mSlotId));
mTabHost.setOnTabChangedListener(mTabListener);
return view;
} else {
mSlotId = componenterList.get(0).getSimSlotIndex();
return super.onCreateView(inflater, container, savedInstanceState);
}
}
@@ -293,17 +328,20 @@ public class IccLockSettings extends SettingsPreferenceFragment
private void updatePreferences() {
final List<SubscriptionInfo> subInfoList =
mProxySubscriptionMgr.getActiveSubscriptionsInfo();
final SubscriptionInfo sir = getActiveSubscriptionInfoForSimSlotIndex(subInfoList, mSlotId);
mSubId = (sir == null) ? SubscriptionManager.INVALID_SUBSCRIPTION_ID
: sir.getSubscriptionId();
final SubscriptionInfo sir = getVisibleSubscriptionInfoForSimSlotIndex(mSlotId);
final int subId = (sir != null) ? sir.getSubscriptionId()
: SubscriptionManager.INVALID_SUBSCRIPTION_ID;
if (mSubId != subId) {
mSubId = subId;
resetDialogState();
if ((mPinDialog != null) && mPinDialog.isDialogOpen()) {
mPinDialog.getDialog().dismiss();
}
}
if (mPinDialog != null) {
mPinDialog.setEnabled(sir != null);
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
mPinDialog.getDialog().dismiss();
}
}
if (mPinToggle != null) {
mPinToggle.setEnabled(sir != null);
@@ -355,6 +393,7 @@ public class IccLockSettings extends SettingsPreferenceFragment
// dialog state. In other cases, where this activity manually launches
// the dialog, store the state of the dialog.
if (mPinDialog.isDialogOpen()) {
out.putInt(DIALOG_SUB_ID, mSubId);
out.putInt(DIALOG_STATE, mDialogState);
out.putString(DIALOG_PIN, mPinDialog.getEditText().getText().toString());
out.putString(DIALOG_ERROR, mError);
@@ -370,11 +409,6 @@ public class IccLockSettings extends SettingsPreferenceFragment
out.putString(OLD_PINCODE, mOldPin);
out.putString(NEW_PINCODE, mNewPin);
break;
case ICC_LOCK_MODE:
case ICC_OLD_MODE:
default:
break;
}
} else {
super.onSaveInstanceState(out);
@@ -672,23 +706,50 @@ public class IccLockSettings extends SettingsPreferenceFragment
mDialogState = OFF_MODE;
}
private static SubscriptionInfo getActiveSubscriptionInfoForSimSlotIndex(
List<SubscriptionInfo> subInfoList, int slotId) {
private String getTagForSlotId(int slotId) {
return String.valueOf(slotId);
}
private int getSlotIndexFromTag(String tag) {
int slotId = -1;
try {
slotId = Integer.parseInt(tag);
} catch (NumberFormatException exception) {
}
return slotId;
}
private SubscriptionInfo getVisibleSubscriptionInfoForSimSlotIndex(int slotId) {
final List<SubscriptionInfo> subInfoList =
mProxySubscriptionMgr.getActiveSubscriptionsInfo();
if (subInfoList == null) {
return null;
}
final CarrierConfigManager carrierConfigManager = getContext().getSystemService(
CarrierConfigManager.class);
for (SubscriptionInfo subInfo : subInfoList) {
if (subInfo.getSimSlotIndex() == slotId) {
if ((isSubscriptionVisible(carrierConfigManager, subInfo)
&& (subInfo.getSimSlotIndex() == slotId))) {
return subInfo;
}
}
return null;
}
private boolean isSubscriptionVisible(CarrierConfigManager carrierConfigManager,
SubscriptionInfo subInfo) {
final PersistableBundle bundle = carrierConfigManager
.getConfigForSubId(subInfo.getSubscriptionId());
if (bundle == null) {
return false;
}
return !bundle.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL);
}
private OnTabChangeListener mTabListener = new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
mSlotId = Integer.parseInt(tabId);
mSlotId = getSlotIndexFromTag(tabId);
// The User has changed tab; update the body.
updatePreferences();

View File

@@ -22,7 +22,6 @@ import static androidx.lifecycle.Lifecycle.Event.ON_START;
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
import android.app.Activity;
import android.os.Build;
import android.view.Window;
import android.view.WindowManager;
@@ -30,6 +29,8 @@ import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import com.android.settings.development.OverlaySettingsPreferenceController;
/**
* A mixin that adds window flag to prevent non-system overlays showing on top of Settings
@@ -45,7 +46,7 @@ public class HideNonSystemOverlayMixin implements LifecycleObserver {
@VisibleForTesting
boolean isEnabled() {
return !Build.IS_DEBUGGABLE;
return !OverlaySettingsPreferenceController.isOverlaySettingsEnabled(mActivity);
}
@OnLifecycleEvent(ON_START)

View File

@@ -26,11 +26,12 @@ import android.os.UserManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.NetworkPolicyEditor;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.datausage.lib.DataUsageLib;
import com.android.settingslib.NetworkPolicyEditor;
public class BillingCyclePreferenceController extends BasePreferenceController {
private int mSubscriptionId;
@@ -58,7 +59,7 @@ public class BillingCyclePreferenceController extends BasePreferenceController {
services.mSubscriptionManager = mContext.getSystemService(SubscriptionManager.class);
services.mUserManager = mContext.getSystemService(UserManager.class);
NetworkTemplate template = DataUsageUtils.getMobileTemplate(mContext, mSubscriptionId);
NetworkTemplate template = DataUsageLib.getMobileTemplate(mContext, mSubscriptionId);
preference.setTemplate(template, mSubscriptionId, services);
}

View File

@@ -33,6 +33,7 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.datausage.lib.DataUsageLib;
import com.android.settings.network.ProxySubscriptionManager;
import com.android.settingslib.NetworkPolicyEditor;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -166,7 +167,7 @@ public class DataUsageSummary extends DataUsageBaseFragment implements DataUsage
private void addMobileSection(int subId, SubscriptionInfo subInfo) {
TemplatePreferenceCategory category = (TemplatePreferenceCategory)
inflatePreferences(R.xml.data_usage_cellular);
category.setTemplate(DataUsageUtils.getMobileTemplate(getContext(), subId),
category.setTemplate(DataUsageLib.getMobileTemplate(getContext(), subId),
subId, services);
category.pushTemplates(services);
if (subInfo != null && !TextUtils.isEmpty(subInfo.getDisplayName())) {

View File

@@ -39,6 +39,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.internal.util.CollectionUtils;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.datausage.lib.DataUsageLib;
import com.android.settings.network.ProxySubscriptionManager;
import com.android.settings.network.telephony.TelephonyBasePreferenceController;
import com.android.settings.widget.EntityHeaderController;
@@ -134,7 +135,7 @@ public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenc
if (subInfo != null) {
mDataUsageTemplate = R.string.cell_data_template;
mDefaultTemplate = DataUsageUtils.getMobileTemplate(context, subscriptionId);
mDefaultTemplate = DataUsageLib.getMobileTemplate(context, subscriptionId);
} else if (DataUsageUtils.hasWifiRadio(context)) {
mDataUsageTemplate = R.string.wifi_data_template;
mDefaultTemplate = NetworkTemplate.buildTemplateWifiWildcard();

View File

@@ -33,6 +33,7 @@ import android.text.format.Formatter;
import android.text.format.Formatter.BytesResult;
import android.util.Log;
import com.android.settings.datausage.lib.DataUsageLib;
import com.android.settings.network.ProxySubscriptionManager;
import java.util.List;
@@ -183,7 +184,7 @@ public final class DataUsageUtils extends com.android.settingslib.net.DataUsageU
*/
public static NetworkTemplate getDefaultTemplate(Context context, int defaultSubId) {
if (SubscriptionManager.isValidSubscriptionId(defaultSubId) && hasMobileData(context)) {
return getMobileTemplate(context, defaultSubId);
return DataUsageLib.getMobileTemplate(context, defaultSubId);
} else if (hasWifiRadio(context)) {
return NetworkTemplate.buildTemplateWifiWildcard();
} else {

View File

@@ -0,0 +1,78 @@
/*
* Copyright (C) 2020 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.datausage.lib;
import android.content.Context;
import android.net.NetworkTemplate;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.android.internal.util.ArrayUtils;
import java.util.List;
/**
* Lib class for data usage
*/
public class DataUsageLib {
private static final String TAG = "DataUsageLib";
/**
* Return mobile NetworkTemplate based on {@code subId}
*/
public static NetworkTemplate getMobileTemplate(Context context, int subId) {
final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class);
final int mobileDefaultSubId = telephonyManager.getSubscriptionId();
final SubscriptionManager subscriptionManager =
context.getSystemService(SubscriptionManager.class);
final List<SubscriptionInfo> subInfoList =
subscriptionManager.getAvailableSubscriptionInfoList();
if (subInfoList == null) {
Log.i(TAG, "Subscription is not inited: " + subId);
return getMobileTemplateForSubId(telephonyManager, mobileDefaultSubId);
}
for (SubscriptionInfo subInfo : subInfoList) {
if ((subInfo != null) && (subInfo.getSubscriptionId() == subId)) {
return getNormalizedMobileTemplate(telephonyManager, subId);
}
}
Log.i(TAG, "Subscription is not active: " + subId);
return getMobileTemplateForSubId(telephonyManager, mobileDefaultSubId);
}
private static NetworkTemplate getNormalizedMobileTemplate(
TelephonyManager telephonyManager, int subId) {
final NetworkTemplate mobileTemplate = getMobileTemplateForSubId(telephonyManager, subId);
final String[] mergedSubscriberIds = telephonyManager
.createForSubscriptionId(subId).getMergedImsisFromGroup();
if (ArrayUtils.isEmpty(mergedSubscriberIds)) {
Log.i(TAG, "mergedSubscriberIds is null.");
return mobileTemplate;
}
return NetworkTemplate.normalize(mobileTemplate, mergedSubscriberIds);
}
private static NetworkTemplate getMobileTemplateForSubId(
TelephonyManager telephonyManager, int subId) {
return NetworkTemplate.buildTemplateMobileAll(telephonyManager.getSubscriberId(subId));
}
}

View File

@@ -539,6 +539,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
controllers.add(new BluetoothHDAudioPreferenceController(context, lifecycle,
bluetoothA2dpConfigStore, fragment));
controllers.add(new SharedDataPreferenceController(context));
controllers.add(new OverlaySettingsPreferenceController(context));
return controllers;
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright (C) 2020 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.development;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
/**
* A controller helps enable or disable a developer setting which allows non system overlays on
* Settings app.
*/
public class OverlaySettingsPreferenceController extends DeveloperOptionsPreferenceController
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
public static final String SHARE_PERFS = "overlay_settings";
private static final String KEY_OVERLAY_SETTINGS = "overlay_settings";
public OverlaySettingsPreferenceController(Context context) {
super(context);
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public String getPreferenceKey() {
return KEY_OVERLAY_SETTINGS;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
setOverlaySettingsEnabled(mContext, (Boolean) newValue);
return true;
}
@Override
public void updateState(Preference preference) {
((SwitchPreference) preference).setChecked(isOverlaySettingsEnabled(mContext));
}
/**
* Check if this setting is enabled or not.
*/
public static boolean isOverlaySettingsEnabled(Context context) {
final SharedPreferences editor = context.getSharedPreferences(SHARE_PERFS,
Context.MODE_PRIVATE);
return editor.getBoolean(SHARE_PERFS, false /* defValue */);
}
/**
* Enable this setting.
*/
@VisibleForTesting
static void setOverlaySettingsEnabled(Context context, boolean enabled) {
final SharedPreferences editor = context.getSharedPreferences(SHARE_PERFS,
Context.MODE_PRIVATE);
editor.edit().putBoolean(SHARE_PERFS, enabled).apply();
}
@Override
protected void onDeveloperOptionsSwitchDisabled() {
super.onDeveloperOptionsSwitchDisabled();
setOverlaySettingsEnabled(mContext, false);
}
}

View File

@@ -22,6 +22,7 @@ import android.os.PowerManager;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.text.TextUtils;
import com.android.settingslib.fuelgauge.BatterySaverUtils;
/**
@@ -112,6 +113,10 @@ public class BatterySaverScheduleRadioButtonsController {
if (mode != PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC) {
Settings.Global.putInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, triggerLevel);
}
// Suppress battery saver suggestion notification if enabling scheduling battery saver.
if (mode == PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC || triggerLevel != 0) {
BatterySaverUtils.suppressAutoBatterySaver(mContext);
}
mSeekBarController.updateSeekBar();
return true;
}

View File

@@ -29,6 +29,7 @@ import androidx.preference.Preference;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.datausage.DataUsageUtils;
import com.android.settings.datausage.lib.DataUsageLib;
import com.android.settingslib.net.DataUsageController;
import com.android.settingslib.utils.ThreadUtils;
@@ -99,7 +100,7 @@ public class DataUsagePreferenceController extends TelephonyBasePreferenceContro
if (!SubscriptionManager.isValidSubscriptionId(subId)) {
return null;
}
return DataUsageUtils.getMobileTemplate(context, subId);
return DataUsageLib.getMobileTemplate(context, subId);
}
private NetworkTemplate getNetworkTemplate() {

View File

@@ -20,7 +20,8 @@ import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTE
import static com.google.common.truth.Truth.assertThat;
import android.os.Build;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.WindowManager;
@@ -28,6 +29,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.android.settings.R;
import com.android.settings.development.OverlaySettingsPreferenceController;
import org.junit.Before;
import org.junit.Test;
@@ -35,7 +37,6 @@ import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
public class HideNonSystemOverlayMixinTest {
@@ -69,17 +70,27 @@ public class HideNonSystemOverlayMixinTest {
}
@Test
public void isEnabled_debug_false() {
ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", true);
public void isEnabled_isAllowedOverlaySettings_returnFalse() {
mActivityController.setup();
final TestActivity activity = mActivityController.get();
final SharedPreferences editor = activity.getSharedPreferences(
OverlaySettingsPreferenceController.SHARE_PERFS,
Context.MODE_PRIVATE);
editor.edit().putBoolean(OverlaySettingsPreferenceController.SHARE_PERFS, true).apply();
assertThat(new HideNonSystemOverlayMixin(null).isEnabled()).isFalse();
assertThat(new HideNonSystemOverlayMixin(activity).isEnabled()).isFalse();
}
@Test
public void isEnabled_user_true() {
ReflectionHelpers.setStaticField(Build.class, "IS_DEBUGGABLE", false);
public void isEnabled_isNotAllowedOverlaySettings_returnTrue() {
mActivityController.setup();
TestActivity activity = mActivityController.get();
final SharedPreferences editor = activity.getSharedPreferences(
OverlaySettingsPreferenceController.SHARE_PERFS,
Context.MODE_PRIVATE);
editor.edit().putBoolean(OverlaySettingsPreferenceController.SHARE_PERFS, false).apply();
assertThat(new HideNonSystemOverlayMixin(null).isEnabled()).isTrue();
assertThat(new HideNonSystemOverlayMixin(activity).isEnabled()).isTrue();
}
public static class TestActivity extends AppCompatActivity {

View File

@@ -0,0 +1,113 @@
/*
* Copyright (C) 2020 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.datausage.lib;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.net.NetworkTemplate;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
public class DataUsageLibTest {
private static final int SUB_ID = 1;
private static final int SUB_ID_2 = 2;
private static final String SUBSCRIBER_ID = "Test Subscriber";
private static final String SUBSCRIBER_ID_2 = "Test Subscriber 2";
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private SubscriptionManager mSubscriptionManager;
@Mock
private SubscriptionInfo mInfo1;
@Mock
private SubscriptionInfo mInfo2;
@Mock
private ParcelUuid mParcelUuid;
private Context mContext;
private List<SubscriptionInfo> mInfos;
@Before
public void setUp() throws RemoteException {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mTelephonyManager.getSubscriberId(SUB_ID)).thenReturn(SUBSCRIBER_ID);
when(mTelephonyManager.getSubscriberId(SUB_ID_2)).thenReturn(SUBSCRIBER_ID_2);
when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
when(mSubscriptionManager.isActiveSubscriptionId(anyInt())).thenReturn(true);
}
@Test
@Ignore
public void getMobileTemplate_infoNull_returnMobileAll() {
when(mSubscriptionManager.isActiveSubscriptionId(SUB_ID)).thenReturn(false);
final NetworkTemplate networkTemplate = DataUsageLib.getMobileTemplate(mContext, SUB_ID);
assertThat(networkTemplate.matchesSubscriberId(SUBSCRIBER_ID)).isTrue();
assertThat(networkTemplate.matchesSubscriberId(SUBSCRIBER_ID_2)).isFalse();
}
@Test
@Ignore
public void getMobileTemplate_groupUuidNull_returnMobileAll() {
when(mSubscriptionManager.getActiveSubscriptionInfo(SUB_ID)).thenReturn(mInfo1);
when(mInfo1.getGroupUuid()).thenReturn(null);
when(mTelephonyManager.getMergedImsisFromGroup())
.thenReturn(new String[] {SUBSCRIBER_ID});
final NetworkTemplate networkTemplate = DataUsageLib.getMobileTemplate(mContext, SUB_ID);
assertThat(networkTemplate.matchesSubscriberId(SUBSCRIBER_ID)).isTrue();
assertThat(networkTemplate.matchesSubscriberId(SUBSCRIBER_ID_2)).isFalse();
}
@Test
@Ignore
public void getMobileTemplate_groupUuidExist_returnMobileMerged() {
when(mSubscriptionManager.getActiveSubscriptionInfo(SUB_ID)).thenReturn(mInfo1);
when(mInfo1.getGroupUuid()).thenReturn(mParcelUuid);
when(mTelephonyManager.getMergedImsisFromGroup())
.thenReturn(new String[] {SUBSCRIBER_ID, SUBSCRIBER_ID_2});
final NetworkTemplate networkTemplate = DataUsageLib.getMobileTemplate(mContext, SUB_ID);
assertThat(networkTemplate.matchesSubscriberId(SUBSCRIBER_ID)).isTrue();
assertThat(networkTemplate.matchesSubscriberId(SUBSCRIBER_ID_2)).isTrue();
}
}

View File

@@ -0,0 +1,120 @@
/*
* Copyright (C) 2020 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.development;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.preference.SwitchPreference;
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 OverlaySettingsPreferenceControllerTest {
private Context mContext;
private SwitchPreference mPreference;
private OverlaySettingsPreferenceController mController;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mController = new OverlaySettingsPreferenceController(mContext);
mPreference = new SwitchPreference(mContext);
}
@Test
public void isAvailable_shouldReturnTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void updateState_isOverlaySettingsEnabled_shouldCheckPreference() {
OverlaySettingsPreferenceController.setOverlaySettingsEnabled(mContext, true);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
}
@Test
public void updateState_isOverlaySettingsDisabled_shouldUncheckPreference() {
OverlaySettingsPreferenceController.setOverlaySettingsEnabled(mContext, false);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse();
}
@Test
public void onPreferenceChange_preferenceChecked_shouldEnableSettings() {
mController.onPreferenceChange(mPreference, true);
assertThat(OverlaySettingsPreferenceController.isOverlaySettingsEnabled(mContext)).isTrue();
}
@Test
public void onPreferenceChange_preferenceUnchecked_shouldDisableSettings() {
mController.onPreferenceChange(mPreference, false);
assertThat(
OverlaySettingsPreferenceController.isOverlaySettingsEnabled(mContext)).isFalse();
}
@Test
public void isOverlaySettingsEnabled_sharePreferenceSetTrue_shouldReturnTrue() {
final SharedPreferences editor = mContext.getSharedPreferences(
OverlaySettingsPreferenceController.SHARE_PERFS,
Context.MODE_PRIVATE);
editor.edit().putBoolean(OverlaySettingsPreferenceController.SHARE_PERFS, true).apply();
assertThat(OverlaySettingsPreferenceController.isOverlaySettingsEnabled(mContext)).isTrue();
}
@Test
public void isOverlaySettingsEnabled_sharePreferenceSetFalse_shouldReturnFalse() {
final SharedPreferences editor = mContext.getSharedPreferences(
OverlaySettingsPreferenceController.SHARE_PERFS,
Context.MODE_PRIVATE);
editor.edit().putBoolean(OverlaySettingsPreferenceController.SHARE_PERFS, false).apply();
assertThat(
OverlaySettingsPreferenceController.isOverlaySettingsEnabled(mContext)).isFalse();
}
@Test
public void setOverlaySettingsEnabled_setTrue_shouldStoreTrue() {
OverlaySettingsPreferenceController.setOverlaySettingsEnabled(mContext, true);
assertThat(
OverlaySettingsPreferenceController.isOverlaySettingsEnabled(mContext)).isTrue();
}
@Test
public void setOverlaySettingsEnabled_setFalse_shouldStoreTrue() {
OverlaySettingsPreferenceController.setOverlaySettingsEnabled(mContext, false);
assertThat(
OverlaySettingsPreferenceController.isOverlaySettingsEnabled(mContext)).isFalse();
}
}

View File

@@ -8,6 +8,7 @@ import android.os.PowerManager;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.provider.Settings.Secure;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -59,9 +60,36 @@ public class BatterySaverScheduleRadioButtonsControllerTest {
@Test
public void setDefaultKey_any_defaultsToNoScheduleIfWarningNotSeen() {
Secure.putString(
mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, "null");
mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, "null");
mController.setDefaultKey(BatterySaverScheduleRadioButtonsController.KEY_ROUTINE);
assertThat(mController.getDefaultKey())
.isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_NO_SCHEDULE);
}
@Test
public void setDefaultKey_percentage_shouldSuppressNotification() {
Secure.putInt(
mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 1);
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
Settings.Global.putInt(mResolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 5);
mController.setDefaultKey(BatterySaverScheduleRadioButtonsController.KEY_PERCENTAGE);
final int result = Settings.Secure.getInt(mResolver,
Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 0);
assertThat(result).isEqualTo(1);
}
@Test
public void setDefaultKey_routine_shouldSuppressNotification() {
Secure.putInt(
mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 1);
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC);
mController.setDefaultKey(BatterySaverScheduleRadioButtonsController.KEY_ROUTINE);
final int result = Settings.Secure.getInt(mResolver,
Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 0);
assertThat(result).isEqualTo(1);
}
}

View File

@@ -36,6 +36,8 @@ import androidx.lifecycle.LiveData;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.slice.Slice;
import androidx.slice.SliceProvider;
import androidx.slice.widget.SliceLiveData;
import com.android.settings.R;
import com.android.settings.homepage.contextualcards.ContextualCard;
@@ -79,6 +81,7 @@ public class SliceContextualCardRendererTest {
mLifecycleOwner = new ContextualCardsFragment();
mRenderer = new SliceContextualCardRenderer(mActivity, mLifecycleOwner,
mControllerRendererPool);
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
}
@Test