• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
16 package com.android.settings.dashboard.conditional;
17 
18 import android.content.Intent;
19 import android.graphics.drawable.Drawable;
20 import android.net.NetworkPolicyManager;
21 import android.util.FeatureFlagUtils;
22 
23 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
24 import com.android.settings.R;
25 import com.android.settings.Settings;
26 import com.android.settings.core.FeatureFlags;
27 
28 public class BackgroundDataCondition extends Condition {
29 
BackgroundDataCondition(ConditionManager manager)30     public BackgroundDataCondition(ConditionManager manager) {
31         super(manager);
32     }
33 
34     @Override
refreshState()35     public void refreshState() {
36         setActive(NetworkPolicyManager.from(mManager.getContext()).getRestrictBackground());
37     }
38 
39     @Override
getIcon()40     public Drawable getIcon() {
41         return mManager.getContext().getDrawable(R.drawable.ic_data_saver);
42     }
43 
44     @Override
getTitle()45     public CharSequence getTitle() {
46         return mManager.getContext().getString(R.string.condition_bg_data_title);
47     }
48 
49     @Override
getSummary()50     public CharSequence getSummary() {
51         return mManager.getContext().getString(R.string.condition_bg_data_summary);
52     }
53 
54     @Override
getActions()55     public CharSequence[] getActions() {
56         return new CharSequence[] {mManager.getContext().getString(R.string.condition_turn_off)};
57     }
58 
59     @Override
onPrimaryClick()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
getMetricsConstant()70     public int getMetricsConstant() {
71         return MetricsEvent.SETTINGS_CONDITION_BACKGROUND_DATA;
72     }
73 
74     @Override
onActionClick(int index)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