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 #include "atm_command.h"
17
18 #include "accesstoken_kit.h"
19 #include "status_receiver_host.h"
20
21 namespace OHOS {
22 namespace Security {
23 namespace AccessToken {
AtmCommand(int argc,char * argv[])24 AtmCommand::AtmCommand(int argc, char *argv[]) : ShellCommand(argc, argv, TOOLS_NAME)
25 {}
26
CreateCommandMap()27 ErrCode AtmCommand::CreateCommandMap()
28 {
29 commandMap_ = {
30 {"help", std::bind(&AtmCommand::RunAsHelpCommand, this)},
31 {"dump", std::bind(&AtmCommand::RunAsDumpCommand, this)},
32 };
33
34 return OHOS::ERR_OK;
35 }
36
CreateMessageMap()37 ErrCode AtmCommand::CreateMessageMap()
38 {
39 messageMap_ = {
40 };
41
42 return OHOS::ERR_OK;
43 }
44
init()45 ErrCode AtmCommand::init()
46 {
47 ErrCode result = OHOS::ERR_OK;
48
49 // there is no need to get proxy currently, the function used in class AccessTokenKit is static
50
51 return result;
52 }
53
RunAsHelpCommand()54 ErrCode AtmCommand::RunAsHelpCommand()
55 {
56 resultReceiver_.append(HELP_MSG);
57
58 return OHOS::ERR_OK;
59 }
60
RunAsDumpCommand()61 ErrCode AtmCommand::RunAsDumpCommand()
62 {
63 int result = OHOS::ERR_OK;
64 std::string tokenInfo = "";
65
66 AccessTokenKit::DumpTokenInfo(tokenInfo);
67 resultReceiver_ = tokenInfo + "\n";
68
69 return result;
70 }
71 } // namespace AccessToken
72 } // namespace Security
73 } // namespace OHOS
74