1 /*
2  * Copyright (C) 2021 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.car.settings.datausage;
18 
19 import android.net.NetworkPolicyManager;
20 import android.net.NetworkTemplate;
21 import android.os.Bundle;
22 
23 import androidx.annotation.Nullable;
24 import androidx.annotation.StringRes;
25 
26 import com.android.car.settings.R;
27 
28 /** Screen used to pick the data usage limit threshold bytes. */
29 public class DataLimitSetThresholdFragment extends DataUsageSetThresholdBaseFragment {
30 
31     /**
32      * Creates a new instance of {@link DataLimitSetThresholdFragment} with the given template. If
33      * the template is {@code null}, the fragment will use the default data network template.
34      */
newInstance(@ullable NetworkTemplate template)35     public static DataLimitSetThresholdFragment newInstance(@Nullable NetworkTemplate template) {
36         DataLimitSetThresholdFragment fragment = new DataLimitSetThresholdFragment();
37         Bundle args = new Bundle();
38         args.putParcelable(NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE, template);
39         fragment.setArguments(args);
40         return fragment;
41     }
42 
43     @Override
onSave(long threshold)44     void onSave(long threshold) {
45         mPolicyEditor.setPolicyLimitBytes(mNetworkTemplate, threshold);
46     }
47 
48     @Override
49     @StringRes
getTitleResId()50     protected int getTitleResId() {
51         return R.string.data_usage_limit_editor_title;
52     }
53 
54     @Override
getInitialBytes()55     protected long getInitialBytes() {
56         return mPolicyEditor.getPolicyLimitBytes(mNetworkTemplate);
57     }
58 }
59