1 /*
2  * Copyright (C) 2022 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 REQUEST_H
17 #define REQUEST_H
18 
19 #include <list>
20 #include <string>
21 
22 #include "i_locator_callback.h"
23 #include "request_config.h"
24 #include "app_identity.h"
25 
26 namespace OHOS {
27 namespace Location {
28 class Request {
29 public:
30     Request();
31     Request(std::unique_ptr<RequestConfig>& requestConfig,
32         sptr<ILocatorCallback>& callback, AppIdentity &identity);
33     ~Request();
34     pid_t GetUid();
35     pid_t GetPid();
36     std::string GetPackageName();
37     sptr<RequestConfig> GetRequestConfig();
38     sptr<ILocatorCallback> GetLocatorCallBack();
39     std::string GetUuid();
40     void SetUid(pid_t uid);
41     void SetPid(pid_t pid);
42     void SetPackageName(std::string packageName);
43     void SetRequestConfig(RequestConfig& requestConfig);
44     void SetLocatorCallBack(const sptr<ILocatorCallback>& callback);
45     void SetUuid(std::string uuid);
46     std::string ToString() const;
47     void GetProxyName(std::shared_ptr<std::list<std::string>> proxys);
48     bool GetIsRequesting();
49     void SetRequesting(bool state);
50     sptr<Location> GetLastLocation();
51     void SetLastLocation(const std::unique_ptr<Location>& location);
52     sptr<Location> GetBestLocation();
53     void SetBestLocation(const std::unique_ptr<Location>& location);
54     uint32_t GetTokenId();
55     uint32_t GetFirstTokenId();
56     uint64_t GetTokenIdEx();
57     int GetPermUsedType();
58     void SetPermUsedType(int type);
59     void SetTokenId(uint32_t tokenId);
60     void SetFirstTokenId(uint32_t firstTokenId);
61     void SetTokenIdEx(uint64_t tokenIdEx);
62     bool GetLocationPermState();
63     bool GetBackgroundPermState();
64     bool GetApproximatelyPermState();
65     void SetLocationPermState(bool state);
66     void SetBackgroundPermState(bool state);
67     void SetApproximatelyPermState(bool state);
68     void SetNlpRequestType(int nlpRequestType);
69     int GetNlpRequestType();
70     void SetNlpRequestType();
71     void SetLocationErrorCallBack(const sptr<ILocatorCallback>& callback);
72     sptr<ILocatorCallback> GetLocationErrorCallBack();
73     void SetLocatorCallbackRecipient(const sptr<IRemoteObject::DeathRecipient>& recipient);
74     sptr<IRemoteObject::DeathRecipient> GetLocatorCallbackRecipient();
75 private:
76     void GetProxyNameByPriority(std::shared_ptr<std::list<std::string>> proxys);
77 
78     pid_t uid_;
79     pid_t pid_;
80     uint32_t tokenId_;
81     uint64_t tokenIdEx_;
82     uint32_t firstTokenId_;
83     int nlpRequestType_;
84     sptr<Location> lastLocation_;
85     sptr<Location> bestLocation_;
86     std::string packageName_;
87     std::string uuid_;
88     sptr<RequestConfig> requestConfig_;
89     sptr<ILocatorCallback> callBack_;
90     sptr<ILocatorCallback> locationErrorcallBack_;
91     bool isRequesting_;
92     bool isUsingLocationPerm_;
93     bool isUsingBackgroundPerm_;
94     bool isUsingApproximatelyPerm_;
95     int permUsedType_;
96     sptr<IRemoteObject::DeathRecipient> locatorCallbackRecipient_;
97 };
98 } // namespace Location
99 } // namespace OHOS
100 #endif // REQUEST_H
101