Merge test folder of test branch
[iotivity.git] / test / src / iBtestapp / modules / cs / android / src / org / iotivity / test / cs / app / Action.java
1 /******************************************************************
2  *
3  * Copyright 2017 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 package org.iotivity.test.cs.app;
22
23 import android.content.Context;
24 import android.util.Log;
25
26 import org.iotivity.base.ModeType;
27 import org.iotivity.base.OcAccountManager;
28 import org.iotivity.base.OcCloudProvisioning;
29 import org.iotivity.base.OcPlatform;
30 import org.iotivity.base.PlatformConfig;
31 import org.iotivity.base.QualityOfService;
32 import org.iotivity.base.ServiceType;
33 import org.iotivity.cloud.OcAccountManagerHelper;
34 import org.iotivity.configuration.IConfiguration;
35 import org.iotivity.test.cs.app.CSConstants;
36 import org.iotivity.test.cs.app.OcCloudProvisioningHelper;
37 import org.iotivity.service.testapp.framework.Base;
38
39 import java.io.File;
40 import java.util.ArrayList;
41
42 public class Action extends Base implements IConfiguration {
43
44     private OcAccountManagerHelper    mCloudHelper               = new OcAccountManagerHelper();
45     private OcCloudProvisioningHelper mOcCloudProvisioningHelper = new OcCloudProvisioningHelper();
46     public OcCloudProvisioning        mOcCloudProvisioning       = new OcCloudProvisioning(
47             OcCloudProvisioningHelper.DEFAULT_HOST_IP,
48             OcCloudProvisioningHelper.DEFAULT_PORT);
49     private OcAccountManager          mAccountManager;
50     private Context                   context;
51
52     public Action(Context context1) {
53         Log.i(CSConstants.TAG, "Action Contructor called.");
54     }
55
56     public void startCloudControlee() {
57         showOutPut("Start CS Client");
58
59         context = getContext();
60         // create platform config
61         mOcCloudProvisioningHelper.copyCborFromAsset(context,
62                 CSConstants.OIC_CLIENT_CBOR_DB_FILE);
63         OcCloudProvisioningHelper.mFilePath = context.getFilesDir().getPath()
64                 + "/"; // data/data/<package>/files/
65         PlatformConfig cfg = new PlatformConfig(context, ServiceType.IN_PROC,
66                 ModeType.CLIENT_SERVER, "0.0.0.0", // bind to all available
67                 // interfaces
68                 0, QualityOfService.LOW, OcCloudProvisioningHelper.mFilePath
69                         + CSConstants.OIC_CLOUD_CLIENT);
70
71         OcPlatform.Configure(cfg);
72         mAccountManager = OcAccountManagerHelper
73                 .getAccountMangerInstance(TLS.DISABLED);
74
75         OcAccountManagerHelper.init(OcCloudProvisioningHelper.mFilePath);
76     }
77
78     public void signUp() {
79         showOutPut("signUp");
80         mCloudHelper.singUp(mAccountManager, DEFAULT_AUTH_PROVIDER,
81                 OcAccountManagerHelper.s_mAuthCode, mCloudHelper);
82     }
83
84     public void signIn() {
85         showOutPut("signIn");
86         mCloudHelper.singIn(mAccountManager, OcAccountManagerHelper.s_mCloudUid,
87                 OcAccountManagerHelper.s_mCloudAccessToken, mCloudHelper);
88     }
89
90     public void signOut() {
91         showOutPut("signOut");
92         mCloudHelper.singOut(mAccountManager,
93                 OcAccountManagerHelper.s_mCloudAccessToken, mCloudHelper);
94     }
95
96     public void cloudCertificateIssueRequest() {
97         showOutPut("cloudCertificateIssueRequest");
98         mOcCloudProvisioningHelper.requestCertificate(mOcCloudProvisioning,
99                 mOcCloudProvisioningHelper);
100     }
101
102     public void cloudGetCRL() {
103         showOutPut("cloudGetCRL");
104         mOcCloudProvisioningHelper.getCRL(mOcCloudProvisioning,
105                 mOcCloudProvisioningHelper);
106     }
107
108     public void cloudPostCRL() {
109         showOutPut("cloudPostCRL");
110         ArrayList<String> serialNumbers = new ArrayList<String>();
111         serialNumbers.add(CSConstants.CERT_SERIAL_ONE);
112         mOcCloudProvisioningHelper.postCRL(mOcCloudProvisioning,
113                 OcCloudProvisioningHelper.thisUpdate,
114                 OcCloudProvisioningHelper.nextUpdate, CSConstants.DEFAULT_CRL,
115                 serialNumbers, mOcCloudProvisioningHelper);
116     }
117
118     public void cloudGetAclIdByDevice() {
119         showOutPut("cloudGetAclIdByDevice");
120         mOcCloudProvisioningHelper.getAclIdByDevice(mOcCloudProvisioning,
121                 OcCloudProvisioningHelper.DEFAULT_DEVICE_ID,
122                 mOcCloudProvisioningHelper);
123     }
124
125     public void cloudAclIndividualGetInfo() {
126         showOutPut("cloudAclIndividualGetInfo");
127         mOcCloudProvisioningHelper.getIndividualAclInfo(mOcCloudProvisioning,
128                 OcCloudProvisioningHelper.DEFAULT_ACL_ID,
129                 mOcCloudProvisioningHelper);
130     }
131
132     public void clearLog() {
133         showOutPut("Clearing Log");
134         clearOutPut();
135     }
136 }