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