blob: 062e734424de87637f587a2ded92aab57a2d9fcd [file] [log] [blame]
Ta-wei Yen8a6f86c2016-05-25 11:32:32 -07001/*
2 * Copyright (C) 2016 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
17package com.android.phone;
18
19import android.content.ContentResolver;
20import android.content.ContentValues;
21import android.content.Context;
22import android.net.Uri;
23import android.provider.VoicemailContract;
24import android.provider.VoicemailContract.Status;
25import android.telecom.PhoneAccountHandle;
Ta-wei Yenf5c5d932016-06-01 19:40:24 -070026
27import com.android.phone.vvm.omtp.utils.PhoneAccountHandleConverter;
Ta-wei Yen8a6f86c2016-05-25 11:32:32 -070028
29public class VoicemailStatus {
30
31
32 public static class Editor {
33
34 private final Context mContext;
35 private final PhoneAccountHandle mPhoneAccountHandle;
36
37 private ContentValues mValues = new ContentValues();
38
39 private Editor(Context context, PhoneAccountHandle phoneAccountHandle) {
40 mContext = context;
41 mPhoneAccountHandle = phoneAccountHandle;
42 }
43
44 public Editor setType(String type) {
45 mValues.put(Status.SOURCE_TYPE, type);
46 return this;
47 }
48
49 public Editor setConfigurationState(int configurationState) {
50 mValues.put(Status.CONFIGURATION_STATE, configurationState);
51 return this;
52 }
53
54 public Editor setDataChannelState(int dataChannelState) {
55 mValues.put(Status.DATA_CHANNEL_STATE, dataChannelState);
56 return this;
57 }
58
59 public Editor setNotificationChannelState(int notificationChannelState) {
60 mValues.put(Status.NOTIFICATION_CHANNEL_STATE, notificationChannelState);
61 return this;
62 }
63
64 public Editor setQuota(int occupied, int total) {
65 if (occupied == VoicemailContract.Status.QUOTA_UNAVAILABLE
66 && total == VoicemailContract.Status.QUOTA_UNAVAILABLE) {
67 return this;
68 }
69
70 mValues.put(Status.QUOTA_OCCUPIED, occupied);
71 mValues.put(Status.QUOTA_TOTAL, total);
72 return this;
73 }
74
75 public void apply() {
76 mValues.put(Status.PHONE_ACCOUNT_COMPONENT_NAME,
77 mPhoneAccountHandle.getComponentName().flattenToString());
78 mValues.put(Status.PHONE_ACCOUNT_ID, mPhoneAccountHandle.getId());
79 ContentResolver contentResolver = mContext.getContentResolver();
80 Uri statusUri = VoicemailContract.Status.buildSourceUri(mContext.getPackageName());
81 contentResolver.insert(statusUri, mValues);
82 }
83 }
84
85 public static Editor edit(Context context, PhoneAccountHandle phoneAccountHandle) {
86 return new Editor(context, phoneAccountHandle);
87 }
88
89 public static Editor edit(Context context, int subId) {
Ta-wei Yenf5c5d932016-06-01 19:40:24 -070090 return new Editor(context, PhoneAccountHandleConverter.fromSubId(subId));
Ta-wei Yen8a6f86c2016-05-25 11:32:32 -070091 }
92}