• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.datausage;
18 
19 import android.content.Context;
20 import android.net.INetworkStatsService;
21 import android.net.NetworkPolicyManager;
22 import android.net.NetworkTemplate;
23 import android.os.INetworkManagementService;
24 import android.os.ServiceManager;
25 import android.os.UserManager;
26 import android.telephony.SubscriptionManager;
27 import android.telephony.TelephonyManager;
28 
29 import androidx.preference.PreferenceScreen;
30 
31 import com.android.settings.core.BasePreferenceController;
32 import com.android.settings.datausage.lib.DataUsageLib;
33 import com.android.settingslib.NetworkPolicyEditor;
34 
35 public class BillingCyclePreferenceController extends BasePreferenceController {
36     private int mSubscriptionId;
37 
BillingCyclePreferenceController(Context context, String preferenceKey)38     public BillingCyclePreferenceController(Context context, String preferenceKey) {
39         super(context, preferenceKey);
40     }
41 
init(int subscriptionId)42     public void init(int subscriptionId) {
43         mSubscriptionId = subscriptionId;
44     }
45 
46     @Override
displayPreference(PreferenceScreen screen)47     public void displayPreference(PreferenceScreen screen) {
48         super.displayPreference(screen);
49         BillingCyclePreference preference = screen.findPreference(getPreferenceKey());
50 
51         TemplatePreference.NetworkServices services = new TemplatePreference.NetworkServices();
52         services.mNetworkService = INetworkManagementService.Stub.asInterface(
53                 ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
54         services.mStatsService = INetworkStatsService.Stub.asInterface(
55                 ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
56         services.mPolicyManager = mContext.getSystemService(NetworkPolicyManager.class);
57         services.mPolicyEditor = new NetworkPolicyEditor(services.mPolicyManager);
58         services.mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
59         services.mSubscriptionManager = mContext.getSystemService(SubscriptionManager.class);
60         services.mUserManager = mContext.getSystemService(UserManager.class);
61 
62         NetworkTemplate template = DataUsageLib.getMobileTemplate(mContext, mSubscriptionId);
63 
64         preference.setTemplate(template, mSubscriptionId, services);
65     }
66 
67     @Override
getAvailabilityStatus()68     public int getAvailabilityStatus() {
69         return AVAILABLE;
70     }
71 }
72