1 /* 2 * Copyright (C) 2018 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 17 package com.android.settings.homepage.contextualcards.conditional; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.net.NetworkPolicyManager; 23 24 import com.android.settings.R; 25 import com.android.settings.Settings; 26 import com.android.settings.homepage.contextualcards.ContextualCard; 27 28 import java.util.Objects; 29 30 public class BackgroundDataConditionController implements ConditionalCardController { 31 static final int ID = Objects.hash("BackgroundDataConditionController"); 32 33 private final Context mAppContext; 34 private final ConditionManager mConditionManager; 35 private final NetworkPolicyManager mNetworkPolicyManager; 36 BackgroundDataConditionController(Context appContext, ConditionManager manager)37 public BackgroundDataConditionController(Context appContext, ConditionManager manager) { 38 mAppContext = appContext; 39 mConditionManager = manager; 40 mNetworkPolicyManager = 41 (NetworkPolicyManager) appContext.getSystemService(Context.NETWORK_POLICY_SERVICE); 42 } 43 44 @Override getId()45 public long getId() { 46 return ID; 47 } 48 49 @Override isDisplayable()50 public boolean isDisplayable() { 51 return mNetworkPolicyManager.getRestrictBackground(); 52 } 53 54 @Override onPrimaryClick(Context context)55 public void onPrimaryClick(Context context) { 56 context.startActivity(new Intent(context, Settings.DataUsageSummaryActivity.class)); 57 } 58 59 @Override onActionClick()60 public void onActionClick() { 61 mNetworkPolicyManager.setRestrictBackground(false); 62 mConditionManager.onConditionChanged(); 63 } 64 65 @Override buildContextualCard()66 public ContextualCard buildContextualCard() { 67 return new ConditionalContextualCard.Builder() 68 .setConditionId(ID) 69 .setMetricsConstant(SettingsEnums.SETTINGS_CONDITION_BACKGROUND_DATA) 70 .setActionText(mAppContext.getText(R.string.condition_turn_off)) 71 .setName(mAppContext.getPackageName() + "/" 72 + mAppContext.getText(R.string.condition_bg_data_title)) 73 .setTitleText(mAppContext.getText(R.string.condition_bg_data_title).toString()) 74 .setSummaryText(mAppContext.getText(R.string.condition_bg_data_summary).toString()) 75 .setIconDrawable(mAppContext.getDrawable(R.drawable.ic_data_saver)) 76 .setViewType(ConditionContextualCardRenderer.VIEW_TYPE_HALF_WIDTH) 77 .build(); 78 } 79 80 @Override startMonitoringStateChange()81 public void startMonitoringStateChange() { 82 83 } 84 85 @Override stopMonitoringStateChange()86 public void stopMonitoringStateChange() { 87 88 } 89 } 90