1a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos/*
2a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos * Copyright (C) 2014 The Android Open Source Project
3a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos *
4a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos * Licensed under the Apache License, Version 2.0 (the "License");
5a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos * you may not use this file except in compliance with the License.
6a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos * You may obtain a copy of the License at
7a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos *
8a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos *      http://www.apache.org/licenses/LICENSE-2.0
9a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos *
10a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos * Unless required by applicable law or agreed to in writing, software
11a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos * distributed under the License is distributed on an "AS IS" BASIS,
12a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos * See the License for the specific language governing permissions and
14a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos * limitations under the License
15a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos */
16a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos
17a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roospackage com.android.trustagent.test;
18a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos
19a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roosimport android.annotation.Nullable;
20a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roosimport android.app.Activity;
21a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roosimport android.os.Bundle;
22a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roosimport android.view.View;
23a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roosimport android.widget.CheckBox;
24a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roosimport android.widget.CompoundButton;
25a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos
26a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roospublic class SampleTrustAgentSettings extends Activity implements View.OnClickListener,
27a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        CompoundButton.OnCheckedChangeListener {
28a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos
29a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    private static final int TRUST_DURATION_MS = 30 * 1000;
30a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos
31a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    private CheckBox mReportUnlockAttempts;
327861c663fd64af33ec2a4c5ad653c806dc8bd994Adrian Roos    private CheckBox mManagingTrust;
33a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos
34a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    @Override
35a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    protected void onCreate(@Nullable Bundle savedInstanceState) {
36a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        super.onCreate(savedInstanceState);
37a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        setContentView(R.layout.sample_trust_agent_settings);
38a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos
39a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        findViewById(R.id.enable_trust).setOnClickListener(this);
40a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        findViewById(R.id.revoke_trust).setOnClickListener(this);
41c5f95cea2639b698594a85acbde6a5519941d7b1Adrian Roos        findViewById(R.id.crash).setOnClickListener(this);
42a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos
43a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        mReportUnlockAttempts = (CheckBox) findViewById(R.id.report_unlock_attempts);
44a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        mReportUnlockAttempts.setOnCheckedChangeListener(this);
457861c663fd64af33ec2a4c5ad653c806dc8bd994Adrian Roos
467861c663fd64af33ec2a4c5ad653c806dc8bd994Adrian Roos        mManagingTrust = (CheckBox) findViewById(R.id.managing_trust);
477861c663fd64af33ec2a4c5ad653c806dc8bd994Adrian Roos        mManagingTrust.setOnCheckedChangeListener(this);
48a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    }
49a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos
50a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    @Override
51a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    protected void onResume() {
52a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        super.onResume();
53a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        mReportUnlockAttempts.setChecked(SampleTrustAgent.getReportUnlockAttempts(this));
547861c663fd64af33ec2a4c5ad653c806dc8bd994Adrian Roos        mManagingTrust.setChecked(SampleTrustAgent.getIsManagingTrust(this));
55a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    }
56a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos
57a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    @Override
58a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    public void onClick(View v) {
59a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        int id = v.getId();
60a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        if (id == R.id.enable_trust) {
617e03dfcb796ef1a6000a5fd5fda03c9e15ea62e1Adrian Roos            SampleTrustAgent.sendGrantTrust(this, "SampleTrustAgent", TRUST_DURATION_MS,
622bb8bfd1e85c8359412159fde57dd5722f5be58cAdrian Roos                    false /* initiatedByUser */);
63a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        } else if (id == R.id.revoke_trust) {
64a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos            SampleTrustAgent.sendRevokeTrust(this);
65c5f95cea2639b698594a85acbde6a5519941d7b1Adrian Roos        } else if (id == R.id.crash) {
66c5f95cea2639b698594a85acbde6a5519941d7b1Adrian Roos            throw new RuntimeException("crash");
67a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        }
68a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    }
69a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos
70a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    @Override
71a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
727861c663fd64af33ec2a4c5ad653c806dc8bd994Adrian Roos        if (buttonView == mReportUnlockAttempts) {
73a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos            SampleTrustAgent.setReportUnlockAttempts(this, isChecked);
747861c663fd64af33ec2a4c5ad653c806dc8bd994Adrian Roos        } else if (buttonView == mManagingTrust) {
757861c663fd64af33ec2a4c5ad653c806dc8bd994Adrian Roos            SampleTrustAgent.setIsManagingTrust(this, isChecked);
76a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos        }
77a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos    }
78a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos}
79