SampleTrustAgentSettings.java revision 7e03dfcb796ef1a6000a5fd5fda03c9e15ea62e1
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; 32a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos 33a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos @Override 34a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos protected void onCreate(@Nullable Bundle savedInstanceState) { 35a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos super.onCreate(savedInstanceState); 36a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos setContentView(R.layout.sample_trust_agent_settings); 37a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos 38a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos findViewById(R.id.enable_trust).setOnClickListener(this); 39a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos findViewById(R.id.revoke_trust).setOnClickListener(this); 40a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos 41a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos mReportUnlockAttempts = (CheckBox) findViewById(R.id.report_unlock_attempts); 42a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos mReportUnlockAttempts.setOnCheckedChangeListener(this); 43a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos } 44a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos 45a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos @Override 46a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos protected void onResume() { 47a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos super.onResume(); 48a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos mReportUnlockAttempts.setChecked(SampleTrustAgent.getReportUnlockAttempts(this)); 49a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos } 50a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos 51a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos @Override 52a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos public void onClick(View v) { 53a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos int id = v.getId(); 54a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos if (id == R.id.enable_trust) { 557e03dfcb796ef1a6000a5fd5fda03c9e15ea62e1Adrian Roos SampleTrustAgent.sendGrantTrust(this, "SampleTrustAgent", TRUST_DURATION_MS, 56a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos null /* extra */); 57a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos } else if (id == R.id.revoke_trust) { 58a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos SampleTrustAgent.sendRevokeTrust(this); 59a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos } 60a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos } 61a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos 62a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos @Override 63a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 64a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos if (buttonView.getId() == R.id.report_unlock_attempts) { 65a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos SampleTrustAgent.setReportUnlockAttempts(this, isChecked); 66a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos } 67a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos } 68a3dafcfb26117e3a2efa3983bd7ba79ae6831680Adrian Roos} 69