• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "pbap_pce_connected_state.h"
17 #include <codecvt>
18 #include <locale>
19 #include "pbap_pce_service.h"
20 #include "power_manager.h"
21 
22 namespace OHOS {
23 namespace bluetooth {
PceConnectedState(const std::string & name,PbapPceStateMachine & stm,BaseObserverList<IPbapPceObserver> & observerMgrList)24 PceConnectedState::PceConnectedState(
25     const std::string &name, PbapPceStateMachine &stm, BaseObserverList<IPbapPceObserver> &observerMgrList)
26     : PceBaseState(name, stm, observerMgrList)
27 {}
28 
Entry()29 void PceConnectedState::Entry()
30 {
31     PBAP_PCE_LOG_INFO("%{public}s start", __PRETTY_FUNCTION__);
32     PBAP_PCE_LOG_INFO("%{public}s, observer->OnServiceConnectionStateChanged", __PRETTY_FUNCTION__);
33     auto &device = stm_.GetDevice();
34     IPowerManager::GetInstance().StatusUpdate(RequestStatus::CONNECT_ON, PROFILE_NAME_PBAP_PCE, device);
35     observerMgrList_.ForEach([device](IPbapPceObserver &observer) {
36         observer.OnServiceConnectionStateChanged(device, static_cast<int>(BTConnectState::CONNECTED));
37     });
38     stm_.TransitTargetState();
39     PBAP_PCE_LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
40 }
41 
Exit()42 void PceConnectedState::Exit()
43 {
44     PBAP_PCE_LOG_INFO("%{public}s start", __PRETTY_FUNCTION__);
45     PBAP_PCE_LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
46 }
47 
ReqPullPhoneBook(const utility::Message & msg) const48 void PceConnectedState::ReqPullPhoneBook(const utility::Message &msg) const
49 {
50     auto pullMsg = static_cast<PbapPcePullPhoneBookMsg *>(msg.arg2_);
51     if (!stm_.IsRepositorySupported(pullMsg->GetName())) {
52         std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
53         PBAP_PCE_LOG_ERROR("%{public}s request path=<%{public}s> not supported.",
54                            __PRETTY_FUNCTION__,
55                            converter.to_bytes(pullMsg->GetName()).c_str());
56     }
57     IPbapPullPhoneBookParam param;
58     param.SetName(pullMsg->GetName());
59     param.SetPropertySelector(pullMsg->GetPropertySelector());
60     param.SetFormat(pullMsg->GetFormat());
61     param.SetMaxListCount(pullMsg->GetMaxListCount());
62     param.SetListStartOffset(pullMsg->GetListStartOffset());
63     param.SetResetNewMissedCalls(pullMsg->GetResetNewMissedCalls());
64     param.SetvCardSelector(pullMsg->GetvCardSelector());
65     param.SetvCardSelectorOp(pullMsg->GetvCardSelectorOp());
66     param.SetSpecifiedBitset(pullMsg->GetSpecifiedBitset());
67     stm_.PullPhoneBook(param);
68 }
69 
ReqSetPhoneBook(const utility::Message & msg) const70 void PceConnectedState::ReqSetPhoneBook(const utility::Message &msg) const
71 {
72     auto reqMsg = static_cast<PbapPceSetPhoneBookMsg *>(msg.arg2_);
73     stm_.SetPhoneBook(reqMsg->GetName(), reqMsg->GetFlag());
74 }
75 
ReqPullvCardListing(const utility::Message & msg) const76 void PceConnectedState::ReqPullvCardListing(const utility::Message &msg) const
77 {
78     auto listingMsg = static_cast<PbapPcePullvCardListingMsg *>(msg.arg2_);
79     IPbapPullvCardListingParam param;
80     param.SetName(listingMsg->GetName());
81     param.SetOrder(listingMsg->GetOrder());
82     param.SetSearchValue(listingMsg->GetSearchValue());
83     param.SetSearchProperty(listingMsg->GetSearchProperty());
84     param.SetMaxListCount(listingMsg->GetMaxListCount());
85     param.SetListStartOffset(listingMsg->GetListStartOffset());
86     param.SetResetNewMissedCalls(listingMsg->GetResetNewMissedCalls());
87     param.SetvCardSelector(listingMsg->GetvCardSelector());
88     param.SetvCardSelectorOp(listingMsg->GetvCardSelectorOp());
89     param.SetSpecifiedBitset(listingMsg->GetSpecifiedBitset());
90 
91     stm_.PullvCardListing(param);
92 }
93 
ReqPullvCardEntry(const utility::Message & msg) const94 void PceConnectedState::ReqPullvCardEntry(const utility::Message &msg) const
95 {
96     auto entryMsg = static_cast<PbapPcePullvCardEntryMsg *>(msg.arg2_);
97     IPbapPullvCardEntryParam param;
98     param.SetName(entryMsg->GetName());
99     param.SetPropertySelector(entryMsg->GetPropertySelector());
100     param.SetFormat(entryMsg->GetFormat());
101     param.SetSpecifiedBitset(entryMsg->GetSpecifiedBitset());
102     stm_.PullvCardEntry(param);
103 }
104 
DispatchActionCompleted(const utility::Message & msg) const105 bool PceConnectedState::DispatchActionCompleted(const utility::Message &msg) const
106 {
107     PBAP_PCE_LOG_INFO("%{public}s start, msg.what_=[%{public}d]", __PRETTY_FUNCTION__, msg.what_);
108     bool ret = true;
109 
110     switch (msg.what_) {
111         case PCE_PULLPHONEBOOKSIZE_COMPLETED:
112             stm_.HandlePhoneBookSizeActionCompleted(msg);
113             break;
114         case PCE_PULLPHONEBOOK_COMPLETED:
115             stm_.HandlePullPhoneBookActionCompleted(msg);
116             break;
117         case PCE_SETPHONEBOOK_COMPLETED:
118             stm_.HandleSetPhoneBookActionCompleted(msg);
119             break;
120         case PCE_PULLVCARDLISTINGSIZE_COMPLETED:
121             stm_.HandlePullvCardListingSizeActionCompleted(msg);
122             break;
123         case PCE_PULLVCARDLISTING_COMPLETED:
124             stm_.HandlePullvCardListingActionCompleted(msg);
125             break;
126         case PCE_PULLVCARDENTRY_COMPLETED:
127             stm_.HandlePullvCardEntryActionCompleted(msg);
128             break;
129         case PCE_ABORTDOWNLOADING_COMPLETED:
130             stm_.HandleAbortDownloadingActionCompleted(msg);
131             break;
132         default:
133             ret = false;
134             stm_.TryReleasePbapMsg(msg);
135             PBAP_PCE_LOG_ERROR("%{public}s msg.what_=%{public}d can't be handled.", __PRETTY_FUNCTION__, msg.what_);
136             break;
137     }
138     PBAP_PCE_LOG_INFO("%{public}s end, msg.what_=[%{public}d]", __PRETTY_FUNCTION__, msg.what_);
139     return ret;
140 }
141 
Dispatch(const utility::Message & msg)142 bool PceConnectedState::Dispatch(const utility::Message &msg)
143 {
144     PBAP_PCE_LOG_INFO("%{public}s start, msg.what_=[%{public}d]", __PRETTY_FUNCTION__, msg.what_);
145     bool ret = true;
146 
147     switch (msg.what_) {
148         case PCE_REQ_DISCONNECTED:
149             Transition(PCE_DISCONNECTING_STATE);
150             stm_.ReqDisconnect();
151             break;
152         case PCE_REQ_SET_TARGET_STATE:
153             stm_.SetTargetState(msg.arg1_);
154             break;
155         case PCE_REQ_TRANSIT_TARGET_STATE:
156             stm_.TransitTargetState();
157             break;
158         case PCE_OBEX_DISCONNECTED:
159             Transition(PCE_DISCONNECTING_STATE);
160             Transition(PCE_DISCONNECTED_STATE);
161             break;
162         case PCE_REQ_PULLPHONEBOOK:
163             ReqPullPhoneBook(msg);
164             break;
165         case PCE_REQ_SETPHONEBOOK:
166             ReqSetPhoneBook(msg);
167             break;
168         case PCE_REQ_PULLVCARDLISTING:
169             ReqPullvCardListing(msg);
170             break;
171         case PCE_REQ_PULLVCARDENTRY:
172             ReqPullvCardEntry(msg);
173             break;
174         case PCE_REQ_ABORTDOWNLOADING:
175             stm_.AbortDownloading();
176             break;
177         default:
178             ret = DispatchActionCompleted(msg);
179             break;
180     }
181     PBAP_PCE_LOG_INFO("%{public}s end, msg.what_=[%{public}d]", __PRETTY_FUNCTION__, msg.what_);
182     return ret;
183 }
184 }  // namespace bluetooth
185 }  // namespace OHOS
186