SampleTrustAgentSettings.java revision a3dafcfb26117e3a2efa3983bd7ba79ae6831680
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.preference.CheckBoxPreference;
23import android.view.View;
24import android.widget.CheckBox;
25import android.widget.CompoundButton;
26
27public class SampleTrustAgentSettings extends Activity implements View.OnClickListener,
28        CompoundButton.OnCheckedChangeListener {
29
30    private static final int TRUST_DURATION_MS = 30 * 1000;
31
32    private CheckBox mReportUnlockAttempts;
33
34    @Override
35    protected void onCreate(@Nullable Bundle savedInstanceState) {
36        super.onCreate(savedInstanceState);
37        setContentView(R.layout.sample_trust_agent_settings);
38
39        findViewById(R.id.enable_trust).setOnClickListener(this);
40        findViewById(R.id.revoke_trust).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.sendEnableTrust(this, "SampleTrustAgent", TRUST_DURATION_MS,
57                    null /* extra */);
58        } else if (id == R.id.revoke_trust) {
59            SampleTrustAgent.sendRevokeTrust(this);
60        }
61    }
62
63    @Override
64    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
65        if (buttonView.getId() == R.id.report_unlock_attempts) {
66            SampleTrustAgent.setReportUnlockAttempts(this, isChecked);
67        }
68    }
69}
70