• 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 #ifndef OHOS_REQUEST_SESSION_H
17 #define OHOS_REQUEST_SESSION_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "single_instance.h"
23 #include "dm_app_image_info.h"
24 #include "dm_device_info.h"
25 #include "msg_response_auth.h"
26 
27 namespace OHOS {
28 namespace DistributedHardware {
29 class RequestSession {
30 public:
31     RequestSession(std::string &hostPkgName, std::string &targetPkgName, const DmDeviceInfo &devReqInfo,
32         const DmAppImageInfo &imageInfo);
33     ~RequestSession() = default;
34     std::vector<std::string> GetRequestCommand(std::string &extrasJson);
35     int32_t GetPinToken();
36     void SetChannelId(long long channelId);
37     void Release();
38     bool IsFinished();
39     bool IsMyChannelId(long long channelId);
40     void OnReceiveMsg(std::string &msg);
41     bool IsWaitingForScan();
42     std::string GetToken();
43     bool IsMyPinToken(int32_t pinToken);
44     void OnReceivePinCode(int32_t pinCode);
45     void NotifyHostAppAuthResult(int32_t errorCode);
46     void OnUserOperate(int32_t action);
47     int64_t GetRequestId();
48     std::string GetRequestDeviceId();
49 
50 private:
51     int32_t StartFaService();
52     std::string GetHostPkgName();
53     std::string GetTargetPkgName();
54     int32_t GetSessionType();
55     void CloseChannel();
56     int32_t ParseRespMsg(std::string &msg);
57     void SyncDmPrivateGroup(std::vector<std::string> &remoteGroupList);
58 
59 private:
60     enum StatusType : int32_t {
61         STATUS_INIT = 0,
62         STATUS_WAITING_REPLY = 2,
63         STATUS_WATING_SCAN_OR_INPUT = 3,
64         STATUS_WAITING_ADD_GROUP = 4,
65         STATUS_FINISH = 6,
66     };
67     int32_t mSessionType_ {SESSION_TYPE_IS_APP_AUTH};
68     int32_t mStatus_ {StatusType::STATUS_INIT};
69     std::string mHostPkgName_;
70     std::string mTargetPkgName;
71     std::string mToken_;
72     int32_t mPinToken_ {MIN_PIN_TOKEN};
73     DmDeviceInfo mDevInfo_;
74     DmAppImageInfo mImageInfo_;
75     long long mChannelId_ {-1};
76     bool mIsChannelOpened_ {false};
77     std::string mRemoteDeviceId_;
78     std::string mRemoteNetId_;
79     std::string mRemoteGroupId_;
80     std::string mRemoteGroupName_;
81     int64_t mRequestId_ {-1};
82     std::shared_ptr<MsgResponseAuth> responseMsgPtr_;
83 };
84 }
85 }
86 #endif
87