xref: /aosp_15_r20/frameworks/native/cmds/dumpstate/DumpstateService.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /**
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (c) 2016, The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *     http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #ifndef ANDROID_OS_DUMPSTATE_H_
18*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_OS_DUMPSTATE_H_
19*38e8c45fSAndroid Build Coastguard Worker 
20*38e8c45fSAndroid Build Coastguard Worker #include <mutex>
21*38e8c45fSAndroid Build Coastguard Worker #include <vector>
22*38e8c45fSAndroid Build Coastguard Worker 
23*38e8c45fSAndroid Build Coastguard Worker #include <android-base/unique_fd.h>
24*38e8c45fSAndroid Build Coastguard Worker #include <binder/BinderService.h>
25*38e8c45fSAndroid Build Coastguard Worker 
26*38e8c45fSAndroid Build Coastguard Worker #include "android/os/BnDumpstate.h"
27*38e8c45fSAndroid Build Coastguard Worker #include "dumpstate.h"
28*38e8c45fSAndroid Build Coastguard Worker 
29*38e8c45fSAndroid Build Coastguard Worker namespace android {
30*38e8c45fSAndroid Build Coastguard Worker namespace os {
31*38e8c45fSAndroid Build Coastguard Worker 
32*38e8c45fSAndroid Build Coastguard Worker class DumpstateService : public BinderService<DumpstateService>, public BnDumpstate {
33*38e8c45fSAndroid Build Coastguard Worker   public:
34*38e8c45fSAndroid Build Coastguard Worker     DumpstateService();
35*38e8c45fSAndroid Build Coastguard Worker 
36*38e8c45fSAndroid Build Coastguard Worker     static status_t Start();
37*38e8c45fSAndroid Build Coastguard Worker     static char const* getServiceName();
38*38e8c45fSAndroid Build Coastguard Worker 
39*38e8c45fSAndroid Build Coastguard Worker     status_t dump(int fd, const Vector<String16>& args) override;
40*38e8c45fSAndroid Build Coastguard Worker 
41*38e8c45fSAndroid Build Coastguard Worker     binder::Status preDumpUiData(const std::string& callingPackage) override;
42*38e8c45fSAndroid Build Coastguard Worker 
43*38e8c45fSAndroid Build Coastguard Worker     binder::Status startBugreport(int32_t calling_uid, const std::string& calling_package,
44*38e8c45fSAndroid Build Coastguard Worker                                   android::base::unique_fd bugreport_fd,
45*38e8c45fSAndroid Build Coastguard Worker                                   android::base::unique_fd screenshot_fd, int bugreport_mode,
46*38e8c45fSAndroid Build Coastguard Worker                                   int bugreport_flags, const sp<IDumpstateListener>& listener,
47*38e8c45fSAndroid Build Coastguard Worker                                   bool is_screenshot_requested, bool skip_user_consent) override;
48*38e8c45fSAndroid Build Coastguard Worker 
49*38e8c45fSAndroid Build Coastguard Worker     binder::Status retrieveBugreport(int32_t calling_uid,
50*38e8c45fSAndroid Build Coastguard Worker                                      const std::string& calling_package,
51*38e8c45fSAndroid Build Coastguard Worker                                      int32_t user_id,
52*38e8c45fSAndroid Build Coastguard Worker                                      android::base::unique_fd bugreport_fd,
53*38e8c45fSAndroid Build Coastguard Worker                                      const std::string& bugreport_file,
54*38e8c45fSAndroid Build Coastguard Worker                                      const bool keep_bugreport_on_retrieval,
55*38e8c45fSAndroid Build Coastguard Worker                                      const bool skip_user_consent,
56*38e8c45fSAndroid Build Coastguard Worker                                      const sp<IDumpstateListener>& listener)
57*38e8c45fSAndroid Build Coastguard Worker                                      override;
58*38e8c45fSAndroid Build Coastguard Worker 
59*38e8c45fSAndroid Build Coastguard Worker     binder::Status cancelBugreport(int32_t calling_uid,
60*38e8c45fSAndroid Build Coastguard Worker                                    const std::string& calling_package) override;
61*38e8c45fSAndroid Build Coastguard Worker 
62*38e8c45fSAndroid Build Coastguard Worker   private:
63*38e8c45fSAndroid Build Coastguard Worker     // Dumpstate object which contains all the bugreporting logic.
64*38e8c45fSAndroid Build Coastguard Worker     // Note that dumpstate is a oneshot service, so this object is meant to be used at most for
65*38e8c45fSAndroid Build Coastguard Worker     // one bugreport.
66*38e8c45fSAndroid Build Coastguard Worker     // This service does not own this object.
67*38e8c45fSAndroid Build Coastguard Worker     Dumpstate* ds_;
68*38e8c45fSAndroid Build Coastguard Worker     int32_t calling_uid_;
69*38e8c45fSAndroid Build Coastguard Worker     std::string calling_package_;
70*38e8c45fSAndroid Build Coastguard Worker     std::mutex lock_;
71*38e8c45fSAndroid Build Coastguard Worker };
72*38e8c45fSAndroid Build Coastguard Worker 
73*38e8c45fSAndroid Build Coastguard Worker }  // namespace os
74*38e8c45fSAndroid Build Coastguard Worker }  // namespace android
75*38e8c45fSAndroid Build Coastguard Worker 
76*38e8c45fSAndroid Build Coastguard Worker #endif  // ANDROID_OS_DUMPSTATE_H_
77