1 /* 2 * Copyright (C) 2012 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.Notification; 21 import android.app.NotificationManager; 22 import android.app.admin.DevicePolicyManager; 23 import android.content.Context; 24 import android.content.Intent; 25 import android.os.Bundle; 26 27 import com.android.cts.verifier.R; 28 29 /** 30 * Test activity used to generate a notification. 31 */ 32 public class WorkNotificationTestActivity extends Activity { 33 public static final String ACTION_WORK_NOTIFICATION = 34 "com.android.cts.verifier.managedprovisioning.WORK_NOTIFICATION"; 35 public static final String ACTION_WORK_NOTIFICATION_ON_LOCKSCREEN = 36 "com.android.cts.verifier.managedprovisioning.LOCKSCREEN_NOTIFICATION"; 37 public static final String ACTION_CLEAR_WORK_NOTIFICATION = 38 "com.android.cts.verifier.managedprovisioning.CLEAR_WORK_NOTIFICATION"; 39 private static final int NOTIFICATION_ID = 7; 40 private NotificationManager mNotificationManager; 41 showWorkNotification(int visibility)42 private void showWorkNotification(int visibility) { 43 final Notification notification = new Notification.Builder(this) 44 .setSmallIcon(R.drawable.icon) 45 .setContentTitle(getString(R.string.provisioning_byod_work_notification_title)) 46 .setVisibility(visibility) 47 .setAutoCancel(true) 48 .build(); 49 mNotificationManager.notify(NOTIFICATION_ID, notification); 50 } 51 52 @Override onCreate(Bundle savedInstanceState)53 public void onCreate(Bundle savedInstanceState) { 54 super.onCreate(savedInstanceState); 55 final String action = getIntent().getAction(); 56 mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 57 if (ACTION_WORK_NOTIFICATION.equals(action)) { 58 showWorkNotification(Notification.VISIBILITY_PUBLIC); 59 } else if (ACTION_WORK_NOTIFICATION_ON_LOCKSCREEN.equals(action)) { 60 DevicePolicyManager dpm = (DevicePolicyManager) getSystemService( 61 Context.DEVICE_POLICY_SERVICE); 62 dpm.lockNow(); 63 showWorkNotification(Notification.VISIBILITY_PRIVATE); 64 } else if (ACTION_CLEAR_WORK_NOTIFICATION.equals(action)) { 65 mNotificationManager.cancel(NOTIFICATION_ID); 66 } 67 finish(); 68 } 69 } 70