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.admin.DevicePolicyManager; 20 import android.content.ActivityNotFoundException; 21 import android.content.BroadcastReceiver; 22 import android.content.ComponentName; 23 import android.content.Context; 24 import android.content.Intent; 25 import android.content.IntentFilter; 26 import android.content.pm.PackageManager; 27 import android.hardware.fingerprint.FingerprintManager; 28 import android.os.Bundle; 29 import android.provider.Settings; 30 import android.util.Log; 31 import android.view.View; 32 import android.view.View.OnClickListener; 33 import android.widget.Toast; 34 35 import com.android.cts.verifier.ArrayTestListAdapter; 36 import com.android.cts.verifier.DialogTestListActivity; 37 import com.android.cts.verifier.R; 38 import com.android.cts.verifier.TestResult; 39 40 public class TurnOffWorkActivity extends DialogTestListActivity { 41 42 private static final String TAG = "TurnOffWorkActivity"; 43 private DialogTestListItem mTurnOffWorkTest; 44 private DialogTestListItem mTurnOnWorkTest; 45 46 private BroadcastReceiver mReceiver = new BroadcastReceiver() { 47 @Override 48 public void onReceive(Context content, Intent intent) { 49 if (Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(intent.getAction())) { 50 setTestResult(mTurnOffWorkTest, TestResult.TEST_RESULT_PASSED); 51 } else if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(intent.getAction())) { 52 setTestResult(mTurnOnWorkTest, TestResult.TEST_RESULT_PASSED); 53 } 54 } 55 }; 56 57 public TurnOffWorkActivity() { 58 super(R.layout.provisioning_byod, 59 R.string.provisioning_byod_turn_off_work, 60 R.string.provisioning_byod_turn_off_work_info, 61 R.string.provisioning_byod_turn_off_work_instructions); 62 } 63 64 @Override 65 protected void onCreate(Bundle savedInstanceState) { 66 super.onCreate(savedInstanceState); 67 68 mPrepareTestButton.setText(R.string.provisioning_byod_turn_off_work_prepare_button); 69 mPrepareTestButton.setOnClickListener(new OnClickListener() { 70 @Override 71 public void onClick(View v) { 72 try { 73 startActivity(new Intent(Settings.ACTION_SYNC_SETTINGS)); 74 } catch (ActivityNotFoundException e) { 75 Log.w(TAG, "Cannot start activity.", e); 76 Toast.makeText(TurnOffWorkActivity.this, 77 "Cannot start settings", Toast.LENGTH_SHORT).show(); 78 } 79 } 80 }); 81 setTestResult(mTurnOffWorkTest, TestResult.TEST_RESULT_NOT_EXECUTED); 82 setTestResult(mTurnOnWorkTest, TestResult.TEST_RESULT_NOT_EXECUTED); 83 IntentFilter filter = new IntentFilter(); 84 filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE); 85 filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE); 86 registerReceiver(mReceiver, filter); 87 } 88 89 @Override 90 protected void onDestroy() { 91 super.onDestroy(); 92 unregisterReceiver(mReceiver); 93 } 94 95 @Override 96 protected void setupTests(ArrayTestListAdapter adapter) { 97 final Intent homeIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME); 98 99 adapter.add(new DialogTestListItem(this, 100 R.string.provisioning_byod_turn_off_work_prepare_notifications, 101 "BYOD_TurnOffWorkCreateNotification", 102 R.string.provisioning_byod_turn_off_work_prepare_notifications_instruction, 103 new Intent(ByodHelperActivity.ACTION_NOTIFICATION))); 104 105 mTurnOffWorkTest = new DialogTestListItem(this, 106 R.string.provisioning_byod_turn_off_work_turned_off, 107 "BYOD_WorkTurnedOff") { 108 @Override 109 public void performTest(DialogTestListActivity activity) { 110 Toast.makeText(TurnOffWorkActivity.this, 111 R.string.provisioning_byod_turn_off_work_turned_off_toast, 112 Toast.LENGTH_SHORT).show(); 113 } 114 }; 115 adapter.add(mTurnOffWorkTest); 116 117 adapter.add(new DialogTestListItem(this, 118 R.string.provisioning_byod_turn_off_work_notifications, 119 "BYOD_TurnOffWorkNotifications", 120 R.string.provisioning_byod_turn_off_work_notifications_instruction, 121 new Intent(ByodHelperActivity.ACTION_NOTIFICATION))); 122 123 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) { 124 adapter.add(new DialogTestListItem(this, R.string.provisioning_byod_turn_off_work_launcher, 125 "BYOD_TurnOffWorkStartApps", 126 R.string.provisioning_byod_turn_off_work_launcher_instruction, 127 homeIntent)); 128 } 129 130 mTurnOnWorkTest = new DialogTestListItem(this, 131 R.string.provisioning_byod_turn_off_work_turned_on, 132 "BYOD_WorkTurnedOn") { 133 @Override 134 public void performTest(DialogTestListActivity activity) { 135 Toast.makeText(TurnOffWorkActivity.this, 136 R.string.provisioning_byod_turn_off_work_turned_on_toast, 137 Toast.LENGTH_SHORT).show(); 138 } 139 }; 140 adapter.add(mTurnOnWorkTest); 141 142 adapter.add(new DialogTestListItem(this, R.string.provisioning_byod_turn_on_work_icon, 143 "BYOD_TurnOnWorkIcon", 144 R.string.provisioning_byod_turn_on_work_icon_instruction, 145 new Intent(Settings.ACTION_SETTINGS))); 146 147 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) { 148 adapter.add(new DialogTestListItem(this, R.string.provisioning_byod_turn_on_work_launcher, 149 "BYOD_TurnOnWorkStartApps", 150 R.string.provisioning_byod_turn_on_work_launcher_instruction, 151 homeIntent)); 152 } 153 } 154 } 155