Home | History | Annotate | Download | only in conditional
      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.Icon;
     20 import android.net.NetworkPolicyManager;
     21 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     22 import com.android.settings.R;
     23 import com.android.settings.Settings;
     24 
     25 public class BackgroundDataCondition extends Condition {
     26 
     27     public BackgroundDataCondition(ConditionManager manager) {
     28         super(manager);
     29     }
     30 
     31     @Override
     32     public void refreshState() {
     33         setActive(NetworkPolicyManager.from(mManager.getContext()).getRestrictBackground());
     34     }
     35 
     36     @Override
     37     public Icon getIcon() {
     38         return Icon.createWithResource(mManager.getContext(), R.drawable.ic_data_saver);
     39     }
     40 
     41     @Override
     42     public CharSequence getTitle() {
     43         return mManager.getContext().getString(R.string.condition_bg_data_title);
     44     }
     45 
     46     @Override
     47     public CharSequence getSummary() {
     48         return mManager.getContext().getString(R.string.condition_bg_data_summary);
     49     }
     50 
     51     @Override
     52     public CharSequence[] getActions() {
     53         return new CharSequence[] { mManager.getContext().getString(R.string.condition_turn_off) };
     54     }
     55 
     56     @Override
     57     public void onPrimaryClick() {
     58         mManager.getContext().startActivity(new Intent(mManager.getContext(),
     59                 Settings.DataUsageSummaryActivity.class));
     60     }
     61 
     62     @Override
     63     public int getMetricsConstant() {
     64         return MetricsEvent.SETTINGS_CONDITION_BACKGROUND_DATA;
     65     }
     66 
     67     @Override
     68     public void onActionClick(int index) {
     69         if (index == 0) {
     70             NetworkPolicyManager.from(mManager.getContext()).setRestrictBackground(false);
     71             setActive(false);
     72         } else {
     73             throw new IllegalArgumentException("Unexpected index " + index);
     74         }
     75     }
     76 }
     77