1 /*
2  * Copyright (C) 2015 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.widget.Toast;
23 import android.content.ActivityNotFoundException;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.util.Log;
27 
28 import com.android.cts.verifier.IntentDrivenTestActivity;
29 import com.android.cts.verifier.IntentDrivenTestActivity.ButtonInfo;
30 import com.android.cts.verifier.managedprovisioning.ByodHelperActivity;
31 import com.android.cts.verifier.R;
32 import com.android.cts.verifier.TestListAdapter.TestListItem;
33 
34 public class Utils {
35 
36     private static final String TAG = "CtsVerifierByodUtils";
37     static final int BUGREPORT_NOTIFICATION_ID = 12345;
38 
createInteractiveTestItem(Activity activity, String id, int titleRes, int infoRes, ButtonInfo[] buttonInfos)39     static TestListItem createInteractiveTestItem(Activity activity, String id, int titleRes,
40             int infoRes, ButtonInfo[] buttonInfos) {
41         return TestListItem.newTest(activity, titleRes,
42                 id, new Intent(activity, IntentDrivenTestActivity.class)
43                 .putExtra(IntentDrivenTestActivity.EXTRA_ID, id)
44                 .putExtra(IntentDrivenTestActivity.EXTRA_TITLE, titleRes)
45                 .putExtra(IntentDrivenTestActivity.EXTRA_INFO, infoRes)
46                 .putExtra(IntentDrivenTestActivity.EXTRA_BUTTONS, buttonInfos),
47                 null);
48     }
49 
createInteractiveTestItem(Activity activity, String id, int titleRes, int infoRes, ButtonInfo buttonInfo)50     static TestListItem createInteractiveTestItem(Activity activity, String id, int titleRes,
51             int infoRes, ButtonInfo buttonInfo) {
52         return createInteractiveTestItem(activity, id, titleRes, infoRes,
53                 new ButtonInfo[] { buttonInfo });
54     }
55 
requestDeleteManagedProfile(Context context)56     static void requestDeleteManagedProfile(Context context) {
57         try {
58             Intent intent = new Intent(ByodHelperActivity.ACTION_REMOVE_MANAGED_PROFILE);
59             context.startActivity(intent);
60             String message = context.getString(R.string.provisioning_byod_delete_profile);
61             Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
62         }
63         catch (ActivityNotFoundException e) {
64             Log.d(TAG, "requestDeleteProfileOwner: ActivityNotFoundException", e);
65         }
66     }
67 
showBugreportNotification(Context context, String msg, int notificationId)68     static void showBugreportNotification(Context context, String msg, int notificationId) {
69         NotificationManager mNotificationManager =
70                 (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
71         Notification notification = new Notification.Builder(context)
72                 .setSmallIcon(R.drawable.icon)
73                 .setContentTitle(context.getString(
74                         R.string.device_owner_requesting_bugreport_tests))
75                 .setContentText(msg)
76                 .setStyle(new Notification.BigTextStyle().bigText(msg))
77                 .build();
78         mNotificationManager.notify(notificationId, notification);
79     }
80 }
81