blob: ca01de89b1d6f678bc58623aa7a81ce016ddbfff [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;
26import android.telephony.SubscriptionManager;
27
28public class VoicemailStatus {
29
30
31 public static class Editor {
32
33 private final Context mContext;
34 private final PhoneAccountHandle mPhoneAccountHandle;
35
36 private ContentValues mValues = new ContentValues();
37
38 private Editor(Context context, PhoneAccountHandle phoneAccountHandle) {
39 mContext = context;
40 mPhoneAccountHandle = phoneAccountHandle;
41 }
42
43 public Editor setType(String type) {
44 mValues.put(Status.SOURCE_TYPE, type);
45 return this;
46 }
47
48 public Editor setConfigurationState(int configurationState) {
49 mValues.put(Status.CONFIGURATION_STATE, configurationState);
50 return this;
51 }
52
53 public Editor setDataChannelState(int dataChannelState) {
54 mValues.put(Status.DATA_CHANNEL_STATE, dataChannelState);
55 return this;
56 }
57
58 public Editor setNotificationChannelState(int notificationChannelState) {
59 mValues.put(Status.NOTIFICATION_CHANNEL_STATE, notificationChannelState);
60 return this;
61 }
62
63 public Editor setQuota(int occupied, int total) {
64 if (occupied == VoicemailContract.Status.QUOTA_UNAVAILABLE
65 && total == VoicemailContract.Status.QUOTA_UNAVAILABLE) {
66 return this;
67 }
68
69 mValues.put(Status.QUOTA_OCCUPIED, occupied);
70 mValues.put(Status.QUOTA_TOTAL, total);
71 return this;
72 }
73
74 public void apply() {
75 mValues.put(Status.PHONE_ACCOUNT_COMPONENT_NAME,
76 mPhoneAccountHandle.getComponentName().flattenToString());
77 mValues.put(Status.PHONE_ACCOUNT_ID, mPhoneAccountHandle.getId());
78 ContentResolver contentResolver = mContext.getContentResolver();
79 Uri statusUri = VoicemailContract.Status.buildSourceUri(mContext.getPackageName());
80 contentResolver.insert(statusUri, mValues);
81 }
82 }
83
84 public static Editor edit(Context context, PhoneAccountHandle phoneAccountHandle) {
85 return new Editor(context, phoneAccountHandle);
86 }
87
88 public static Editor edit(Context context, int subId) {
89 PhoneAccountHandle phone = PhoneUtils.makePstnPhoneAccountHandle(
90 SubscriptionManager.getPhoneId(subId));
91 return new Editor(context, phone);
92 }
93}