• 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 com.android.settings.core.BasePreferenceController;
30 import com.android.settingslib.NetworkPolicyEditor;
31 
32 import androidx.preference.PreferenceScreen;
33 
34 public class BillingCyclePreferenceController extends BasePreferenceController {
35     private int mSubscriptionId;
36 
BillingCyclePreferenceController(Context context, String preferenceKey)37     public BillingCyclePreferenceController(Context context, String preferenceKey) {
38         super(context, preferenceKey);
39     }
40 
init(int subscriptionId)41     public void init(int subscriptionId) {
42         mSubscriptionId = subscriptionId;
43     }
44 
45     @Override
displayPreference(PreferenceScreen screen)46     public void displayPreference(PreferenceScreen screen) {
47         super.displayPreference(screen);
48         BillingCyclePreference preference = screen.findPreference(getPreferenceKey());
49 
50         TemplatePreference.NetworkServices services = new TemplatePreference.NetworkServices();
51         services.mNetworkService = INetworkManagementService.Stub.asInterface(
52                 ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
53         services.mStatsService = INetworkStatsService.Stub.asInterface(
54                 ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
55         services.mPolicyManager = mContext.getSystemService(NetworkPolicyManager.class);
56         services.mPolicyEditor = new NetworkPolicyEditor(services.mPolicyManager);
57         services.mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
58         services.mSubscriptionManager = mContext.getSystemService(SubscriptionManager.class);
59         services.mUserManager = mContext.getSystemService(UserManager.class);
60 
61         NetworkTemplate template = DataUsageUtils.getMobileTemplate(mContext, mSubscriptionId);
62 
63         preference.setTemplate(template, mSubscriptionId, services);
64     }
65 
66     @Override
getAvailabilityStatus()67     public int getAvailabilityStatus() {
68         return AVAILABLE;
69     }
70 }
71