Home | History | Annotate | Download | only in managedprovisioning
      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.Activity;
     20 import android.app.admin.DevicePolicyManager;
     21 import android.content.ComponentName;
     22 import android.content.Context;
     23 import android.os.Bundle;
     24 import android.view.View;
     25 import android.widget.EditText;
     26 
     27 import com.android.cts.verifier.R;
     28 
     29 public class SetSupportMessageActivity extends Activity implements View.OnClickListener {
     30     public static final String ACTION_SET_SUPPORT_MSG =
     31             "com.android.cts.verifier.managedprovisioning.action.SET_SUPPORT_MSG";
     32     public static final String EXTRA_SUPPORT_MSG_TYPE =
     33             "com.android.cts.verifier.managedprovisioning.extra.SUPPORT_MSG_TYPE";
     34 
     35     public static final String TYPE_SHORT_MSG = "short-msg";
     36     public static final String TYPE_LONG_MSG = "long-msg";
     37 
     38     private String mType;
     39     private EditText mSupportMessage;
     40     private DevicePolicyManager mDpm;
     41     private ComponentName mAdmin;
     42 
     43     public void onCreate(Bundle savedInstanceState) {
     44         super.onCreate(savedInstanceState);
     45         setContentView(R.layout.set_support_message);
     46         findViewById(R.id.set_default_message).setOnClickListener(this);
     47         findViewById(R.id.set_message).setOnClickListener(this);
     48         findViewById(R.id.clear_message).setOnClickListener(this);
     49         mSupportMessage = (EditText) findViewById(R.id.message_view);
     50 
     51         mType = getIntent().getStringExtra(EXTRA_SUPPORT_MSG_TYPE);
     52         setTitle(TYPE_SHORT_MSG.equals(mType)
     53                 ? R.string.policy_transparency_short_support_msg_label
     54                 : R.string.policy_transparency_long_support_msg_label);
     55         mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
     56         mAdmin = DeviceAdminTestReceiver.getReceiverComponentName();
     57 
     58         mSupportMessage.setText(TYPE_SHORT_MSG.equals(mType)
     59                 ? mDpm.getShortSupportMessage(mAdmin)
     60                 : mDpm.getLongSupportMessage(mAdmin));
     61     }
     62 
     63     @Override
     64     public void onClick(View view) {
     65         String message = null;
     66         switch (view.getId()) {
     67             case R.id.set_default_message: {
     68                 message = getString(TYPE_SHORT_MSG.equals(mType)
     69                         ? R.string.policy_transparency_default_short_msg
     70                         : R.string.policy_transparency_default_long_msg);
     71             } break;
     72             case R.id.set_message: {
     73                 message = mSupportMessage.getText().toString();
     74             } break;
     75             case R.id.clear_message: {
     76                 message = null;
     77             } break;
     78         }
     79         if (TYPE_SHORT_MSG.equals(mType)) {
     80             mDpm.setShortSupportMessage(mAdmin, message);
     81         } else {
     82             mDpm.setLongSupportMessage(mAdmin, message);
     83         }
     84         mSupportMessage.setText(message);
     85     }
     86 }