1 /* 2 * Copyright (C) 2016 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 17 package com.android.cts.verifier.managedprovisioning; 18 19 import android.app.ActionBar; 20 import android.app.Activity; 21 import android.app.admin.DevicePolicyManager; 22 import android.content.ComponentName; 23 import android.content.Context; 24 import android.os.Bundle; 25 import android.view.MenuItem; 26 import android.view.View; 27 import android.widget.EditText; 28 29 import com.android.cts.verifier.R; 30 31 public class SetSupportMessageActivity extends Activity implements View.OnClickListener { 32 public static final String ACTION_SET_SUPPORT_MSG = 33 "com.android.cts.verifier.managedprovisioning.action.SET_SUPPORT_MSG"; 34 public static final String EXTRA_SUPPORT_MSG_TYPE = 35 "com.android.cts.verifier.managedprovisioning.extra.SUPPORT_MSG_TYPE"; 36 37 public static final String TYPE_SHORT_MSG = "short-msg"; 38 public static final String TYPE_LONG_MSG = "long-msg"; 39 40 private String mType; 41 private EditText mSupportMessage; 42 private DevicePolicyManager mDpm; 43 private ComponentName mAdmin; 44 onCreate(Bundle savedInstanceState)45 public void onCreate(Bundle savedInstanceState) { 46 super.onCreate(savedInstanceState); 47 setContentView(R.layout.set_support_message); 48 findViewById(R.id.set_default_message).setOnClickListener(this); 49 findViewById(R.id.set_message).setOnClickListener(this); 50 findViewById(R.id.clear_message).setOnClickListener(this); 51 mSupportMessage = findViewById(R.id.message_view); 52 53 ActionBar actBar = getActionBar(); 54 if (actBar != null) { 55 actBar.setDisplayHomeAsUpEnabled(true); 56 } 57 58 mType = getIntent().getStringExtra(EXTRA_SUPPORT_MSG_TYPE); 59 setTitle(TYPE_SHORT_MSG.equals(mType) 60 ? R.string.policy_transparency_short_support_msg_label 61 : R.string.policy_transparency_long_support_msg_label); 62 mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); 63 mAdmin = DeviceAdminTestReceiver.getReceiverComponentName(); 64 65 mSupportMessage.setText(TYPE_SHORT_MSG.equals(mType) 66 ? mDpm.getShortSupportMessage(mAdmin) 67 : mDpm.getLongSupportMessage(mAdmin)); 68 } 69 70 @Override onClick(View view)71 public void onClick(View view) { 72 String message = null; 73 int id = view.getId(); 74 if (id == R.id.set_default_message) { 75 message = getString(TYPE_SHORT_MSG.equals(mType) 76 ? R.string.policy_transparency_default_short_msg 77 : R.string.policy_transparency_default_long_msg); 78 } else if (id == R.id.set_message) { 79 message = mSupportMessage.getText().toString(); 80 } else if (id == R.id.clear_message) { 81 message = null; 82 } 83 84 if (TYPE_SHORT_MSG.equals(mType)) { 85 mDpm.setShortSupportMessage(mAdmin, message); 86 } else { 87 mDpm.setLongSupportMessage(mAdmin, message); 88 } 89 mSupportMessage.setText(message); 90 } 91 92 @Override onOptionsItemSelected(MenuItem item)93 public boolean onOptionsItemSelected(MenuItem item) { 94 if (item.getItemId() == android.R.id.home) { 95 onBackPressed(); 96 return true; 97 } 98 return super.onOptionsItemSelected(item); 99 } 100 } 101