1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package com.android.settings.dashboard.conditional; 17 18import android.content.Intent; 19import android.graphics.drawable.Drawable; 20import android.net.NetworkPolicyManager; 21import android.util.FeatureFlagUtils; 22 23import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 24import com.android.settings.R; 25import com.android.settings.Settings; 26import com.android.settings.core.FeatureFlags; 27 28public class BackgroundDataCondition extends Condition { 29 30 public BackgroundDataCondition(ConditionManager manager) { 31 super(manager); 32 } 33 34 @Override 35 public void refreshState() { 36 setActive(NetworkPolicyManager.from(mManager.getContext()).getRestrictBackground()); 37 } 38 39 @Override 40 public Drawable getIcon() { 41 return mManager.getContext().getDrawable(R.drawable.ic_data_saver); 42 } 43 44 @Override 45 public CharSequence getTitle() { 46 return mManager.getContext().getString(R.string.condition_bg_data_title); 47 } 48 49 @Override 50 public CharSequence getSummary() { 51 return mManager.getContext().getString(R.string.condition_bg_data_summary); 52 } 53 54 @Override 55 public CharSequence[] getActions() { 56 return new CharSequence[] {mManager.getContext().getString(R.string.condition_turn_off)}; 57 } 58 59 @Override 60 public void onPrimaryClick() { 61 final Class activityClass = FeatureFlagUtils.isEnabled(mManager.getContext(), 62 FeatureFlags.DATA_USAGE_SETTINGS_V2) 63 ? Settings.DataUsageSummaryActivity.class 64 : Settings.DataUsageSummaryLegacyActivity.class; 65 mManager.getContext().startActivity(new Intent(mManager.getContext(), activityClass) 66 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); 67 } 68 69 @Override 70 public int getMetricsConstant() { 71 return MetricsEvent.SETTINGS_CONDITION_BACKGROUND_DATA; 72 } 73 74 @Override 75 public void onActionClick(int index) { 76 if (index == 0) { 77 NetworkPolicyManager.from(mManager.getContext()).setRestrictBackground(false); 78 setActive(false); 79 } else { 80 throw new IllegalArgumentException("Unexpected index " + index); 81 } 82 } 83} 84