Merge "Remove dead code for DataPlanUsageSummary"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c9f1d89dd3
@@ -2383,24 +2383,6 @@
|
||||
android:value="com.android.settings.security.CryptKeeperSettings" />
|
||||
</activity>
|
||||
|
||||
<activity android:name="Settings$DataPlanUsageSummaryActivity"
|
||||
android:label="@string/data_usage_summary_title"
|
||||
android:icon="@drawable/ic_settings_data_usage"
|
||||
android:taskAffinity="">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<intent-filter android:priority="10">
|
||||
<action android:name="com.android.settings.action.SETTINGS" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.ia.wireless" />
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.datausage.DataPlanUsageSummary" />
|
||||
</activity>
|
||||
|
||||
<activity android:name="Settings$DataUsageSummaryActivity"
|
||||
android:label="@string/data_usage_summary_title"
|
||||
android:icon="@drawable/ic_settings_data_usage"
|
||||
|
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2017 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.
|
||||
-->
|
||||
|
||||
<!-- Shows the data plans sync time -->
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@android:id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="@dimen/preference_no_icon_padding_start"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:gravity="end"
|
||||
android:textColor="?android:attr/textColorSecondary"/>
|
@@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2017 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.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="@dimen/preference_no_icon_padding_start"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="16dp">
|
||||
<Button
|
||||
android:id="@+id/manage_data_plans"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/data_plan_usage_manage_plans_button_text"
|
||||
android:textAllCaps="true"
|
||||
style="@style/ActionPrimaryButton" />
|
||||
</FrameLayout>
|
@@ -5745,9 +5745,6 @@
|
||||
<!-- action to select all [CHAR LIMIT=30] -->
|
||||
<string name="select_all">Select all</string>
|
||||
|
||||
<!-- A button that gets displayed in data plan usage preference in settings page to manage data plans [CHAR LIMIT=25] -->
|
||||
<string name="data_plan_usage_manage_plans_button_text">Manage plans</string>
|
||||
|
||||
<!-- Activity title for network data usage summary. [CHAR LIMIT=25] -->
|
||||
<string name="data_usage_summary_title">Data usage</string>
|
||||
<!-- Activity title for Appk data usage summary. [CHAR LIMIT=25] -->
|
||||
|
@@ -1,25 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2017 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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/data_usage_summary_title">
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="data_plan_usage"
|
||||
android:title="@string/usage">
|
||||
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2017 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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/data_usage_summary_title">
|
||||
|
||||
<com.android.settings.datausage.TemplatePreferenceCategory
|
||||
android:key="data_usage_mobile_category"
|
||||
android:title="@string/data_usage_tab_mobile">
|
||||
|
||||
<com.android.settings.datausage.CellDataPreference
|
||||
android:key="data_usage_enable"
|
||||
android:title="@string/data_usage_enable_mobile" />
|
||||
</com.android.settings.datausage.TemplatePreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
@@ -78,7 +78,6 @@ public class Settings extends SettingsActivity {
|
||||
public static class AccountSyncSettingsInAddAccountActivity extends SettingsActivity { /* empty */ }
|
||||
public static class CryptKeeperSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class DeviceAdminSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class DataPlanUsageSummaryActivity extends SettingsActivity { /* empty */ }
|
||||
public static class DataUsageSummaryActivity extends SettingsActivity { /* empty */ }
|
||||
public static class DataUsageSummaryLegacyActivity extends SettingsActivity { /* empty */ }
|
||||
public static class MobileDataUsageListActivity extends SettingsActivity { /* empty */ }
|
||||
|
@@ -733,31 +733,11 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin)
|
||||
|| somethingChanged;
|
||||
|
||||
boolean isDataPlanFeatureEnabled = FeatureFactory.getFactory(this)
|
||||
.getDataPlanFeatureProvider()
|
||||
.isEnabled();
|
||||
|
||||
// When the data plan feature flag is turned on we disable DataUsageSummaryActivity
|
||||
// and enable DataPlanUsageSummaryActivity. When the feature flag is turned off we do the
|
||||
// reverse.
|
||||
|
||||
// Disable DataUsageSummaryActivity if the data plan feature flag is turned on otherwise
|
||||
// disable DataPlanUsageSummaryActivity.
|
||||
somethingChanged = setTileEnabled(
|
||||
new ComponentName(packageName,
|
||||
isDataPlanFeatureEnabled
|
||||
? Settings.DataUsageSummaryActivity.class.getName()
|
||||
: Settings.DataPlanUsageSummaryActivity.class.getName()),
|
||||
false /* enabled */,
|
||||
isAdmin) || somethingChanged;
|
||||
|
||||
// Enable DataUsageSummaryActivity if the data plan feature flag is turned on otherwise
|
||||
// enable DataPlanUsageSummaryActivity.
|
||||
somethingChanged = setTileEnabled(
|
||||
new ComponentName(packageName,
|
||||
isDataPlanFeatureEnabled
|
||||
? Settings.DataPlanUsageSummaryActivity.class.getName()
|
||||
: Settings.DataUsageSummaryActivity.class.getName()),
|
||||
new ComponentName(packageName, Settings.DataUsageSummaryActivity.class.getName()),
|
||||
Utils.isBandwidthControlEnabled() /* enabled */,
|
||||
isAdmin) || somethingChanged;
|
||||
|
||||
|
@@ -33,16 +33,16 @@ import com.android.settings.accessibility.AccessibilitySettings;
|
||||
import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
|
||||
import com.android.settings.accessibility.CaptionPropertiesFragment;
|
||||
import com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment;
|
||||
import com.android.settings.accounts.AccountDashboardFragment;
|
||||
import com.android.settings.accounts.AccountSyncSettings;
|
||||
import com.android.settings.accounts.ChooseAccountActivity;
|
||||
import com.android.settings.accounts.ManagedProfileSettings;
|
||||
import com.android.settings.accounts.AccountDashboardFragment;
|
||||
import com.android.settings.applications.AppAndNotificationDashboardFragment;
|
||||
import com.android.settings.applications.DefaultAppSettings;
|
||||
import com.android.settings.applications.DirectoryAccessDetails;
|
||||
import com.android.settings.applications.ManageDomainUrls;
|
||||
import com.android.settings.applications.ProcessStatsSummary;
|
||||
import com.android.settings.applications.ProcessStatsUi;
|
||||
import com.android.settings.applications.DirectoryAccessDetails;
|
||||
import com.android.settings.applications.UsageAccessDetails;
|
||||
import com.android.settings.applications.VrListenerSettings;
|
||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||
@@ -59,7 +59,6 @@ import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFrag
|
||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragmentOld;
|
||||
import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
|
||||
import com.android.settings.datausage.DataPlanUsageSummary;
|
||||
import com.android.settings.datausage.DataUsageList;
|
||||
import com.android.settings.datausage.DataUsageSummary;
|
||||
import com.android.settings.datausage.DataUsageSummaryLegacy;
|
||||
@@ -188,7 +187,6 @@ public class SettingsGateway {
|
||||
PickupGestureSettings.class.getName(),
|
||||
DoubleTwistGestureSettings.class.getName(),
|
||||
CryptKeeperSettings.class.getName(),
|
||||
DataPlanUsageSummary.class.getName(),
|
||||
DataUsageSummary.class.getName(),
|
||||
DataUsageSummaryLegacy.class.getName(),
|
||||
DreamSettings.class.getName(),
|
||||
@@ -275,7 +273,6 @@ public class SettingsGateway {
|
||||
SupportDashboardActivity.class.getName(),
|
||||
// Home page > Network & Internet
|
||||
Settings.WifiSettingsActivity.class.getName(),
|
||||
Settings.DataPlanUsageSummaryActivity.class.getName(),
|
||||
Settings.DataUsageSummaryActivity.class.getName(),
|
||||
Settings.SimSettingsActivity.class.getName(),
|
||||
// Home page > Connected devices
|
||||
|
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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;
|
||||
|
||||
/**
|
||||
* Feature provider for data plan feature.
|
||||
*/
|
||||
public interface DataPlanFeatureProvider {
|
||||
/**
|
||||
* @return whether data plan feature is enabled.
|
||||
*/
|
||||
boolean isEnabled();
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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;
|
||||
|
||||
import android.os.SystemProperties;
|
||||
|
||||
/**
|
||||
* Impl for data plan feature provider.
|
||||
*/
|
||||
public final class DataPlanFeatureProviderImpl implements DataPlanFeatureProvider {
|
||||
private static final String ENABLE_SETTINGS_DATA_PLAN = "enable.settings.data.plan";
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return SystemProperties.getBoolean(ENABLE_SETTINGS_DATA_PLAN, false /* default */);
|
||||
}
|
||||
}
|
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.DonutView;
|
||||
|
||||
/**
|
||||
* Provides a summary of data plans as preferences on settings page.
|
||||
*/
|
||||
public final class DataPlanSummaryPreference extends Preference {
|
||||
private String mName;
|
||||
private String mDescription;
|
||||
private double mPercentageUsage;
|
||||
private int mUsageTextColor;
|
||||
private int mMeterBackgroundColor;
|
||||
private int mMeterConsumedColor;
|
||||
|
||||
public DataPlanSummaryPreference(Context context) {
|
||||
super(context);
|
||||
setLayoutResource(R.layout.settings_data_plan_summary_preference);
|
||||
}
|
||||
|
||||
public DataPlanSummaryPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setLayoutResource(R.layout.settings_data_plan_summary_preference);
|
||||
}
|
||||
|
||||
public void setName(String planName) {
|
||||
mName = planName;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void setDescription(String planDescription) {
|
||||
mDescription = planDescription;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void setPercentageUsage(double percentageUsage) {
|
||||
mPercentageUsage = percentageUsage;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void setUsageTextColor(@ColorRes int planUsageTextColor) {
|
||||
mUsageTextColor = planUsageTextColor;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void setMeterBackgroundColor(@ColorRes int meterBackgroundColor) {
|
||||
mMeterBackgroundColor = meterBackgroundColor;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void setMeterConsumedColor(@ColorRes int meterConsumedColor) {
|
||||
mMeterConsumedColor = meterConsumedColor;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
holder.setDividerAllowedAbove(false);
|
||||
TextView titleView = (TextView) holder.findViewById(android.R.id.title);
|
||||
titleView.setTextColor(mUsageTextColor);
|
||||
((TextView) holder.findViewById(android.R.id.text1)).setText(mName);
|
||||
((TextView) holder.findViewById(android.R.id.text2)).setText(mDescription);
|
||||
DonutView donutView = (DonutView) holder.findViewById(R.id.donut);
|
||||
donutView.setPercentage(mPercentageUsage);
|
||||
donutView.setMeterBackgroundColor(mMeterBackgroundColor);
|
||||
donutView.setMeterConsumedColor(mMeterConsumedColor);
|
||||
}
|
||||
}
|
@@ -1,359 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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;
|
||||
|
||||
import static android.net.NetworkPolicy.LIMIT_DISABLED;
|
||||
|
||||
import android.annotation.IdRes;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.NetworkPolicy;
|
||||
import android.net.NetworkPolicyManager;
|
||||
import android.net.NetworkTemplate;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.Formatter;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settingslib.NetworkPolicyEditor;
|
||||
import com.android.settingslib.net.DataUsageController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @deprecated This fragment was supposed to be new version of {@link DataUsageSummary} however
|
||||
* unfinished and used nowhere. Keep it in case we may bring it back someday.
|
||||
*/
|
||||
@Deprecated
|
||||
public class DataPlanUsageSummary extends DataUsageBase {
|
||||
|
||||
public static final String KEY_DATA_PLAN_USAGE = "data_plan_usage";
|
||||
|
||||
public static final String KEY_STATUS_HEADER = "status_header";
|
||||
public static final String KEY_LIMIT_SUMMARY = "plan_summary";
|
||||
|
||||
// Mobile data keys
|
||||
public static final String KEY_MOBILE_USAGE_TITLE = "data_usage_mobile_category";
|
||||
public static final String KEY_MOBILE_DATA_USAGE_TOGGLE = "data_usage_enable";
|
||||
|
||||
// Wifi keys
|
||||
public static final String KEY_WIFI_USAGE_TITLE = "wifi_category";
|
||||
public static final String KEY_WIFI_DATA_USAGE = "wifi_data_usage";
|
||||
public static final String KEY_NETWORK_RESTRICTIONS = "network_restrictions";
|
||||
|
||||
private DataUsageController mDataUsageController;
|
||||
private DataUsageInfoController mDataInfoController;
|
||||
private List<DataPlanSummaryPreference> mDataPlanSummaryPreferenceList;
|
||||
private Preference mLimitPreference;
|
||||
private NetworkTemplate mDefaultTemplate;
|
||||
private NetworkRestrictionsPreference mNetworkRestrictionPreference;
|
||||
private WifiManager mWifiManager;
|
||||
private NetworkPolicyEditor mPolicyEditor;
|
||||
|
||||
@Override
|
||||
public int getHelpResource() {
|
||||
return R.string.help_url_data_usage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
|
||||
final Context context = getContext();
|
||||
NetworkPolicyManager policyManager = NetworkPolicyManager.from(context);
|
||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
mPolicyEditor = new NetworkPolicyEditor(policyManager);
|
||||
mDataUsageController = new DataUsageController(context);
|
||||
mDataInfoController = new DataUsageInfoController();
|
||||
|
||||
int defaultSubId = DataUsageUtils.getDefaultSubscriptionId(context);
|
||||
boolean hasMobileData = DataUsageUtils.hasMobileData(context);
|
||||
if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
hasMobileData = false;
|
||||
}
|
||||
mDefaultTemplate = DataUsageUtils.getDefaultTemplate(context, defaultSubId);
|
||||
|
||||
if (hasMobileData) {
|
||||
addDataPlanSection(defaultSubId);
|
||||
}
|
||||
|
||||
if (DataUsageUtils.hasWifiRadio(context)) {
|
||||
addWifiSection();
|
||||
}
|
||||
|
||||
if (hasEthernet(context)) {
|
||||
addEthernetSection();
|
||||
}
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
if (UserManager.get(getContext()).isAdminUser()) {
|
||||
inflater.inflate(R.menu.data_usage, menu);
|
||||
}
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.data_usage_menu_cellular_networks: {
|
||||
final Intent intent = new Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void addDataPlanSection(int defaultSubId) {
|
||||
Context context = getPrefContext();
|
||||
addPreferencesFromResource(R.xml.data_plan_usage);
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
screen.setTitle(context.getString(R.string.data_usage_summary_title));
|
||||
|
||||
PreferenceCategory preferenceCategory =
|
||||
(PreferenceCategory) findPreference(KEY_DATA_PLAN_USAGE);
|
||||
screen.addPreference(preferenceCategory);
|
||||
|
||||
Preference dataPlansSyncTimePreference = new Preference(context);
|
||||
dataPlansSyncTimePreference.setLayoutResource(R.layout.data_plans_sync_time_preference);
|
||||
dataPlansSyncTimePreference.setTitle(MockDataPlanUsage.SYNC_TIME);
|
||||
preferenceCategory.addPreference(dataPlansSyncTimePreference);
|
||||
|
||||
mDataPlanSummaryPreferenceList = new ArrayList<>(MockDataPlanUsage.DATA_PLAN_USAGES.length);
|
||||
for (int i = 0; i < MockDataPlanUsage.DATA_PLAN_USAGES.length; i++) {
|
||||
DataPlanSummaryPreference dataPlanSummaryPreference =
|
||||
new DataPlanSummaryPreference(context);
|
||||
dataPlanSummaryPreference.setKey(KEY_STATUS_HEADER + (i + 1));
|
||||
mDataPlanSummaryPreferenceList.add(dataPlanSummaryPreference);
|
||||
preferenceCategory.addPreference(dataPlanSummaryPreference);
|
||||
}
|
||||
|
||||
Preference preference = new Preference(context);
|
||||
preference.setLayoutResource(R.layout.manage_data_plans_preference);
|
||||
preferenceCategory.addPreference(preference);
|
||||
setPreferenceScreen(screen);
|
||||
|
||||
mLimitPreference = findPreference(KEY_LIMIT_SUMMARY);
|
||||
List<SubscriptionInfo> subscriptions =
|
||||
services.mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||
|
||||
if (subscriptions == null || subscriptions.isEmpty()) {
|
||||
addMobileSection(defaultSubId);
|
||||
}
|
||||
|
||||
for (int i = 0, subscriptionsSize = subscriptions != null ? subscriptions.size() : 0;
|
||||
i < subscriptionsSize; i++) {
|
||||
SubscriptionInfo subInfo = subscriptions.get(i);
|
||||
if (subscriptionsSize > 1) {
|
||||
addMobileSection(subInfo.getSubscriptionId(), subInfo);
|
||||
} else {
|
||||
addMobileSection(subInfo.getSubscriptionId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addMobileSection(int subId) {
|
||||
addMobileSection(subId, null);
|
||||
}
|
||||
|
||||
private void addMobileSection(int subId, SubscriptionInfo subInfo) {
|
||||
TemplatePreferenceCategory category = (TemplatePreferenceCategory)
|
||||
inflatePreferences(R.xml.data_plan_usage_cell_data_preference_screen);
|
||||
category.setTemplate(getNetworkTemplate(subId), subId, services);
|
||||
category.pushTemplates(services);
|
||||
if (subInfo != null && !TextUtils.isEmpty(subInfo.getDisplayName())) {
|
||||
Preference title = category.findPreference(KEY_MOBILE_USAGE_TITLE);
|
||||
title.setTitle(subInfo.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
private void addWifiSection() {
|
||||
TemplatePreferenceCategory category = (TemplatePreferenceCategory)
|
||||
inflatePreferences(R.xml.data_usage_wifi);
|
||||
category.setTemplate(NetworkTemplate.buildTemplateWifiWildcard(), 0 /* subId */, services);
|
||||
mNetworkRestrictionPreference =
|
||||
(NetworkRestrictionsPreference) category.findPreference(KEY_NETWORK_RESTRICTIONS);
|
||||
}
|
||||
|
||||
private void addEthernetSection() {
|
||||
TemplatePreferenceCategory category = (TemplatePreferenceCategory)
|
||||
inflatePreferences(R.xml.data_usage_ethernet);
|
||||
category.setTemplate(NetworkTemplate.buildTemplateEthernet(), 0 /* subId */, services);
|
||||
}
|
||||
|
||||
private Preference inflatePreferences(@IdRes int resId) {
|
||||
PreferenceScreen rootPreferences = getPreferenceManager().inflateFromResource(
|
||||
getPrefContext(), resId, null);
|
||||
Preference pref = rootPreferences.getPreference(0);
|
||||
rootPreferences.removeAll();
|
||||
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
pref.setOrder(screen.getPreferenceCount());
|
||||
screen.addPreference(pref);
|
||||
|
||||
return pref;
|
||||
}
|
||||
|
||||
private NetworkTemplate getNetworkTemplate(int subscriptionId) {
|
||||
NetworkTemplate mobileAll = NetworkTemplate.buildTemplateMobileAll(
|
||||
services.mTelephonyManager.getSubscriberId(subscriptionId));
|
||||
return NetworkTemplate.normalize(mobileAll,
|
||||
services.mTelephonyManager.getMergedSubscriberIds());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateState();
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
DataUsageController.DataUsageInfo info = mDataUsageController.getDataUsageInfo(
|
||||
mDefaultTemplate);
|
||||
|
||||
Context context = getContext();
|
||||
mDataInfoController.updateDataLimit(info,
|
||||
services.mPolicyEditor.getPolicy(mDefaultTemplate));
|
||||
|
||||
// TODO(b/63391323): Get rid of MockDataPlanUsage once we integrate with data plan APIs
|
||||
if (mDataPlanSummaryPreferenceList != null && !mDataPlanSummaryPreferenceList.isEmpty()) {
|
||||
MockDataPlanUsage[] dataPlanUsages = MockDataPlanUsage.getDataPlanUsage();
|
||||
for (int i = 0; i < dataPlanUsages.length; i++) {
|
||||
DataPlanSummaryPreference dataPlanSummaryPreference =
|
||||
mDataPlanSummaryPreferenceList.get(i);
|
||||
MockDataPlanUsage dataPlanUsage = dataPlanUsages[i];
|
||||
dataPlanSummaryPreference.setTitle(dataPlanUsage.mUsage);
|
||||
dataPlanSummaryPreference.setUsageTextColor(dataPlanUsage.mUsageTextColor);
|
||||
dataPlanSummaryPreference.setName(dataPlanUsage.mName);
|
||||
dataPlanSummaryPreference.setPercentageUsage(dataPlanUsage.mPercentageUsage);
|
||||
dataPlanSummaryPreference
|
||||
.setMeterBackgroundColor(dataPlanUsage.mMeterBackgroundColor);
|
||||
dataPlanSummaryPreference.setMeterConsumedColor(dataPlanUsage.mMeterConsumedColor);
|
||||
dataPlanSummaryPreference.setDescription(dataPlanUsage.mDescription);
|
||||
}
|
||||
}
|
||||
|
||||
if (mLimitPreference != null && (info.warningLevel > 0 || info.limitLevel > 0)) {
|
||||
String warning = Formatter.formatFileSize(context, info.warningLevel);
|
||||
String limit = Formatter.formatFileSize(context, info.limitLevel);
|
||||
mLimitPreference.setSummary(getString(info.limitLevel <= 0 ? R.string.cell_warning_only
|
||||
: R.string.cell_warning_and_limit, warning, limit));
|
||||
} else if (mLimitPreference != null) {
|
||||
mLimitPreference.setSummary(null);
|
||||
}
|
||||
|
||||
updateNetworkRestrictionSummary(mNetworkRestrictionPreference);
|
||||
|
||||
PreferenceScreen screen = getPreferenceScreen();
|
||||
for (int i = 1, preferenceCount = screen.getPreferenceCount(); i < preferenceCount; i++) {
|
||||
((TemplatePreferenceCategory) screen.getPreference(i)).pushTemplates(services);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.DATA_USAGE_SUMMARY;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updateNetworkRestrictionSummary(NetworkRestrictionsPreference preference) {
|
||||
if (preference == null) {
|
||||
return;
|
||||
}
|
||||
mPolicyEditor.read();
|
||||
int count = 0;
|
||||
List<WifiConfiguration> configuredNetworks = mWifiManager.getConfiguredNetworks();
|
||||
for (int i = 0, configuredNetworksSize = configuredNetworks.size();
|
||||
i < configuredNetworksSize; i++) {
|
||||
WifiConfiguration config = configuredNetworks.get(i);
|
||||
if (isMetered(config)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
preference.setSummary(getResources().getQuantityString(
|
||||
R.plurals.network_restrictions_summary, count, count));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isMetered(WifiConfiguration config) {
|
||||
if (config.SSID == null) {
|
||||
return false;
|
||||
}
|
||||
final String networkId = config.isPasspoint() ? config.providerFriendlyName : config.SSID;
|
||||
final NetworkPolicy policy =
|
||||
mPolicyEditor.getPolicyMaybeUnquoted(NetworkTemplate.buildTemplateWifi(networkId));
|
||||
if (policy == null) {
|
||||
return false;
|
||||
}
|
||||
if (policy.limitBytes != LIMIT_DISABLED) {
|
||||
return true;
|
||||
}
|
||||
return policy.metered;
|
||||
}
|
||||
|
||||
private static class SummaryProvider
|
||||
implements SummaryLoader.SummaryProvider {
|
||||
|
||||
private final Activity mActivity;
|
||||
private final SummaryLoader mSummaryLoader;
|
||||
private final DataUsageController mDataController;
|
||||
|
||||
public SummaryProvider(Activity activity, SummaryLoader summaryLoader) {
|
||||
mActivity = activity;
|
||||
mSummaryLoader = summaryLoader;
|
||||
mDataController = new DataUsageController(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListening(boolean listening) {
|
||||
if (listening) {
|
||||
DataUsageController.DataUsageInfo info = mDataController.getDataUsageInfo();
|
||||
String used;
|
||||
if (info == null) {
|
||||
used = Formatter.formatFileSize(mActivity, 0);
|
||||
} else if (info.limitLevel <= 0) {
|
||||
used = Formatter.formatFileSize(mActivity, info.usageLevel);
|
||||
} else {
|
||||
used = Utils.formatPercentage(info.usageLevel, info.limitLevel);
|
||||
}
|
||||
mSummaryLoader.setSummary(this,
|
||||
mActivity.getString(R.string.data_usage_summary_format, used));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
|
||||
= SummaryProvider::new;
|
||||
}
|
||||
|
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
/**
|
||||
* Mock data plan usage data.
|
||||
*/
|
||||
@Deprecated // This class is only needed because we don't have working API yet.
|
||||
final class MockDataPlanUsage {
|
||||
static final MockDataPlanUsage[] DATA_PLAN_USAGES = new MockDataPlanUsage[3];
|
||||
static final String SYNC_TIME = "Today 12:24pm";
|
||||
final String mUsage;
|
||||
final int mUsageTextColor;
|
||||
final String mName;
|
||||
final double mPercentageUsage;
|
||||
final int mMeterBackgroundColor;
|
||||
final int mMeterConsumedColor;
|
||||
final String mDescription;
|
||||
|
||||
private MockDataPlanUsage(String usage, int usageTextColor, String name,
|
||||
double percentageUsage, int meterBackgroundColor, int meterConsumedColor,
|
||||
String description) {
|
||||
mUsage = usage;
|
||||
mUsageTextColor = usageTextColor;
|
||||
mName = name;
|
||||
mPercentageUsage = percentageUsage;
|
||||
mMeterBackgroundColor = meterBackgroundColor;
|
||||
mMeterConsumedColor = meterConsumedColor;
|
||||
mDescription = description;
|
||||
}
|
||||
|
||||
static MockDataPlanUsage[] getDataPlanUsage() {
|
||||
DATA_PLAN_USAGES[0] = new MockDataPlanUsage("100 MB and 14 days left",
|
||||
Color.parseColor("#FF5C94F1"), "GigaMaxLite / 1GB", 0.27D,
|
||||
Color.parseColor("#FFDBDCDC"), Color.parseColor("#FF5C94F1"),
|
||||
"Premium plan from Telekomsel");
|
||||
|
||||
DATA_PLAN_USAGES[1] = new MockDataPlanUsage("1.25 GB and 14 days left",
|
||||
Color.parseColor("#FF673AB7"), "GigaMaxLite 4G / 5GB", 0.47D,
|
||||
Color.parseColor("#FFDBDCDC"), Color.parseColor("#FF673AB7"),
|
||||
"Plenty of 4G data");
|
||||
|
||||
DATA_PLAN_USAGES[2] = new MockDataPlanUsage("700 MB and 14 days left",
|
||||
Color.parseColor("#FF4CAF50"), "GigaMaxLite Video / 7GB", 0.67D,
|
||||
Color.parseColor("#FFDBDCDC"), Color.parseColor("#FF4CAF50"),
|
||||
"Use certain video apps for free");
|
||||
return DATA_PLAN_USAGES;
|
||||
}
|
||||
}
|
@@ -27,13 +27,12 @@ import com.android.settings.bluetooth.BluetoothFeatureProvider;
|
||||
import com.android.settings.connecteddevice.SmsMirroringFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||
import com.android.settings.datausage.DataPlanFeatureProvider;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.gestures.AssistGestureFeatureProvider;
|
||||
import com.android.settings.localepicker.LocaleFeatureProvider;
|
||||
import com.android.settings.security.SecurityFeatureProvider;
|
||||
import com.android.settings.search.SearchFeatureProvider;
|
||||
import com.android.settings.security.SecurityFeatureProvider;
|
||||
import com.android.settings.slices.SlicesFeatureProvider;
|
||||
import com.android.settings.users.UserFeatureProvider;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
@@ -104,8 +103,6 @@ public abstract class FeatureFactory {
|
||||
|
||||
public abstract BluetoothFeatureProvider getBluetoothFeatureProvider(Context context);
|
||||
|
||||
public abstract DataPlanFeatureProvider getDataPlanFeatureProvider();
|
||||
|
||||
public abstract SmsMirroringFeatureProvider getSmsMirroringFeatureProvider();
|
||||
|
||||
public abstract SlicesFeatureProvider getSlicesFeatureProvider();
|
||||
|
@@ -35,8 +35,6 @@ import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProviderImpl;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl;
|
||||
import com.android.settings.datausage.DataPlanFeatureProvider;
|
||||
import com.android.settings.datausage.DataPlanFeatureProviderImpl;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProviderImpl;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
@@ -77,7 +75,6 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
private AssistGestureFeatureProvider mAssistGestureFeatureProvider;
|
||||
private UserFeatureProvider mUserFeatureProvider;
|
||||
private BluetoothFeatureProvider mBluetoothFeatureProvider;
|
||||
private DataPlanFeatureProvider mDataPlanFeatureProvider;
|
||||
private SmsMirroringFeatureProvider mSmsMirroringFeatureProvider;
|
||||
private SlicesFeatureProvider mSlicesFeatureProvider;
|
||||
private AccountFeatureProvider mAccountFeatureProvider;
|
||||
@@ -191,14 +188,6 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
return mBluetoothFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataPlanFeatureProvider getDataPlanFeatureProvider() {
|
||||
if (mDataPlanFeatureProvider == null) {
|
||||
mDataPlanFeatureProvider = new DataPlanFeatureProviderImpl();
|
||||
}
|
||||
return mDataPlanFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssistGestureFeatureProvider getAssistGestureFeatureProvider() {
|
||||
if (mAssistGestureFeatureProvider == null) {
|
||||
|
@@ -15,7 +15,6 @@ com.android.settings.applications.VrListenerSettings
|
||||
com.android.settings.inputmethod.UserDictionaryList
|
||||
com.android.settings.datausage.DataSaverSummary
|
||||
com.android.settings.datausage.AppDataUsage
|
||||
com.android.settings.datausage.DataPlanUsageSummary
|
||||
com.android.settings.accessibility.FontSizePreferenceFragmentForSetupWizard
|
||||
com.android.settings.applications.ManageDomainUrls
|
||||
com.android.settings.applications.appinfo.WriteSettingsDetails
|
||||
|
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.widget.DonutView;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class
|
||||
}
|
||||
)
|
||||
public final class DataPlanSummaryPreferenceTest {
|
||||
|
||||
private static final String TEST_PLAN_USAGE = "Test plan usage";
|
||||
private static final String TEST_PLAN_NAME = "Test plan name";
|
||||
private static final String TEST_PLAN_DESCRIPTION = "Test plan description";
|
||||
private static int sPlanUsageTextColor;
|
||||
private static int sMeterBackgroundColor;
|
||||
private static int sMeterConsumedColor;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
sPlanUsageTextColor = Color.parseColor("#FF5C94F1");
|
||||
sMeterBackgroundColor = Color.parseColor("#FFDBDCDC");
|
||||
sMeterConsumedColor = Color.parseColor("#FF5C94F1");
|
||||
}
|
||||
|
||||
private DataPlanSummaryPreference mPreference;
|
||||
private PreferenceViewHolder mHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.string.config_headlineFontFamily, "");
|
||||
Context context = RuntimeEnvironment.application;
|
||||
mPreference = new DataPlanSummaryPreference(context);
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(mPreference.getLayoutResource(),
|
||||
new LinearLayout(context), false);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowResources.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withoutData() {
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
TextView planUsageTextView = (TextView) mHolder.findViewById(android.R.id.title);
|
||||
assertThat(planUsageTextView.getText().toString()).isEmpty();
|
||||
TextView planNameTextView = (TextView) mHolder.findViewById(android.R.id.text1);
|
||||
assertThat(planNameTextView.getText().toString()).isEmpty();
|
||||
TextView planDescriptionTextView = (TextView) mHolder.findViewById(android.R.id.text2);
|
||||
assertThat(planDescriptionTextView.getText().toString()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withData() {
|
||||
mPreference.setTitle(TEST_PLAN_USAGE);
|
||||
mPreference.setUsageTextColor(sPlanUsageTextColor);
|
||||
mPreference.setName(TEST_PLAN_NAME);
|
||||
mPreference.setDescription(TEST_PLAN_DESCRIPTION);
|
||||
mPreference.setPercentageUsage(0.25D);
|
||||
mPreference.setMeterBackgroundColor(sMeterBackgroundColor);
|
||||
mPreference.setMeterConsumedColor(sMeterConsumedColor);
|
||||
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
TextView planUsageTextView = (TextView) mHolder.findViewById(android.R.id.title);
|
||||
assertThat(planUsageTextView.getTextColors().getDefaultColor())
|
||||
.isEqualTo(sPlanUsageTextColor);
|
||||
assertThat(planUsageTextView.getText()).isEqualTo(TEST_PLAN_USAGE);
|
||||
|
||||
TextView planNameTextView = (TextView) mHolder.findViewById(android.R.id.text1);
|
||||
assertThat(planNameTextView.getText()).isEqualTo(TEST_PLAN_NAME);
|
||||
|
||||
TextView planDescriptionTextView = (TextView) mHolder.findViewById(android.R.id.text2);
|
||||
assertThat(planDescriptionTextView.getText()).isEqualTo(TEST_PLAN_DESCRIPTION);
|
||||
|
||||
DonutView donutView = (DonutView) mHolder.findViewById(R.id.donut);
|
||||
assertThat(donutView.getMeterBackgroundColor()).isEqualTo(sMeterBackgroundColor);
|
||||
assertThat(donutView.getMeterConsumedColor()).isEqualTo(sMeterConsumedColor);
|
||||
}
|
||||
}
|
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkPolicy;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.NetworkPolicyEditor;
|
||||
import java.util.ArrayList;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DataPlanUsageSummaryTest {
|
||||
@Mock
|
||||
private ConnectivityManager mManager;
|
||||
|
||||
private Context mContext;
|
||||
private DataPlanUsageSummary mDataUsageSummary;
|
||||
private NetworkPolicyEditor mPolicyEditor;
|
||||
private WifiConfiguration mWifiConfiguration;
|
||||
private NetworkPolicy mNetworkPolicy;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowApplication shadowContext = ShadowApplication.getInstance();
|
||||
shadowContext.setSystemService(Context.CONNECTIVITY_SERVICE, mManager);
|
||||
mContext = shadowContext.getApplicationContext();
|
||||
when(mManager.isNetworkSupported(anyInt())).thenReturn(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateNetworkRestrictionSummary_shouldSetSummary() {
|
||||
mDataUsageSummary = spy(new DataPlanUsageSummary());
|
||||
NetworkRestrictionsPreference preference = mock(NetworkRestrictionsPreference.class);
|
||||
mPolicyEditor = mock(NetworkPolicyEditor.class);
|
||||
WifiManager wifiManager = mock(WifiManager.class);
|
||||
ReflectionHelpers.setField(mDataUsageSummary, "mPolicyEditor", mPolicyEditor);
|
||||
ReflectionHelpers.setField(mDataUsageSummary, "mWifiManager", wifiManager);
|
||||
when(wifiManager.getConfiguredNetworks()).thenReturn(new ArrayList<>());
|
||||
doReturn(mContext.getResources()).when(mDataUsageSummary).getResources();
|
||||
|
||||
mDataUsageSummary.updateNetworkRestrictionSummary(preference);
|
||||
|
||||
verify(preference).setSummary(mContext.getResources().getQuantityString(
|
||||
R.plurals.network_restrictions_summary, 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_noSsid_shouldReturnFalse() {
|
||||
initTest();
|
||||
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_noNetworkPolicy_shouldReturnFalse() {
|
||||
initTest();
|
||||
mWifiConfiguration.SSID = "network1";
|
||||
doReturn(null).when(mPolicyEditor).getPolicyMaybeUnquoted(any());
|
||||
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_policyHasLimit_shouldReturnTrue() {
|
||||
initTest();
|
||||
mWifiConfiguration.SSID = "network1";
|
||||
mNetworkPolicy = mock(NetworkPolicy.class);
|
||||
mNetworkPolicy.limitBytes = 100;
|
||||
doReturn(mNetworkPolicy).when(mPolicyEditor).getPolicyMaybeUnquoted(any());
|
||||
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMetered_noPolicyLimit_shouldReturnMeteredValue() {
|
||||
initTest();
|
||||
mWifiConfiguration.SSID = "network1";
|
||||
mNetworkPolicy = mock(NetworkPolicy.class);
|
||||
mNetworkPolicy.limitBytes = NetworkPolicy.LIMIT_DISABLED;
|
||||
doReturn(mNetworkPolicy).when(mPolicyEditor).getPolicyMaybeUnquoted(any());
|
||||
|
||||
mNetworkPolicy.metered = true;
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isTrue();
|
||||
|
||||
mNetworkPolicy.metered = false;
|
||||
assertThat(mDataUsageSummary.isMetered(mWifiConfiguration)).isFalse();
|
||||
}
|
||||
|
||||
private void initTest() {
|
||||
mDataUsageSummary = new DataPlanUsageSummary();
|
||||
mPolicyEditor = mock(NetworkPolicyEditor.class);
|
||||
ReflectionHelpers.setField(mDataUsageSummary, "mPolicyEditor", mPolicyEditor);
|
||||
mWifiConfiguration = mock(WifiConfiguration.class);
|
||||
}
|
||||
}
|
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class DataPlansSyncTimePreferenceTest {
|
||||
private static final String SYNC_TIME = "Today 12:24pm";
|
||||
|
||||
private Preference mPreference;
|
||||
private PreferenceViewHolder mHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Context context = RuntimeEnvironment.application;
|
||||
mPreference = new Preference(context);
|
||||
mPreference.setLayoutResource(R.layout.data_plans_sync_time_preference);
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate(mPreference.getLayoutResource(),
|
||||
new LinearLayout(context), false);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withData() {
|
||||
mPreference.setTitle(SYNC_TIME);
|
||||
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
TextView syncTimeTextView = (TextView) mHolder.findViewById(android.R.id.title);
|
||||
assertThat(syncTimeTextView.getText()).isEqualTo(SYNC_TIME);
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class ManageDataPlansPreferenceTest {
|
||||
private Preference mPreference;
|
||||
private PreferenceViewHolder mHolder;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setLayoutResource(R.layout.manage_data_plans_preference);
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
View view = inflater.inflate(mPreference.getLayoutResource(),
|
||||
new LinearLayout(mContext), false);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRender_withData() {
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
Button managePlanButton = (Button) mHolder.findViewById(R.id.manage_data_plans);
|
||||
assertThat(managePlanButton.getText())
|
||||
.isEqualTo(mContext.getString(R.string.data_plan_usage_manage_plans_button_text));
|
||||
}
|
||||
}
|
@@ -27,7 +27,6 @@ import com.android.settings.bluetooth.BluetoothFeatureProvider;
|
||||
import com.android.settings.connecteddevice.SmsMirroringFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardFeatureProvider;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||
import com.android.settings.datausage.DataPlanFeatureProvider;
|
||||
import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
|
||||
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
|
||||
import com.android.settings.gestures.AssistGestureFeatureProvider;
|
||||
@@ -62,7 +61,6 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public final UserFeatureProvider userFeatureProvider;
|
||||
public final AssistGestureFeatureProvider assistGestureFeatureProvider;
|
||||
public final BluetoothFeatureProvider bluetoothFeatureProvider;
|
||||
public final DataPlanFeatureProvider dataPlanFeatureProvider;
|
||||
public final SmsMirroringFeatureProvider smsMirroringFeatureProvider;
|
||||
public final SlicesFeatureProvider slicesFeatureProvider;
|
||||
public SearchFeatureProvider searchFeatureProvider;
|
||||
@@ -103,7 +101,6 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
userFeatureProvider = mock(UserFeatureProvider.class);
|
||||
assistGestureFeatureProvider = mock(AssistGestureFeatureProvider.class);
|
||||
bluetoothFeatureProvider = mock(BluetoothFeatureProvider.class);
|
||||
dataPlanFeatureProvider = mock(DataPlanFeatureProvider.class);
|
||||
smsMirroringFeatureProvider = mock(SmsMirroringFeatureProvider.class);
|
||||
slicesFeatureProvider = mock(SlicesFeatureProvider.class);
|
||||
mAccountFeatureProvider = mock(AccountFeatureProvider.class);
|
||||
@@ -174,11 +171,6 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
return bluetoothFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataPlanFeatureProvider getDataPlanFeatureProvider() {
|
||||
return dataPlanFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssistGestureFeatureProvider getAssistGestureFeatureProvider() {
|
||||
return assistGestureFeatureProvider;
|
||||
|
Reference in New Issue
Block a user