1 /*
2  * Copyright (C) 2017 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.devicepolicy.assistapp;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.graphics.Bitmap;
22 import android.os.Bundle;
23 import android.service.voice.VoiceInteractionSession;
24 import android.service.voice.VoiceInteractionSessionService;
25 import android.util.Log;
26 
27 public class MyInteractionSessionService extends VoiceInteractionSessionService {
28     private static final String TAG = "DevicePolicyAssistTest";
29     private static final String ACTION_HANDLE_SCREENSHOT =
30             "voice_interaction_session_service.handle_screenshot";
31     private static final String KEY_HAS_SCREENSHOT = "has_screenshot";
32 
33     @Override
onNewSession(Bundle args)34     public VoiceInteractionSession onNewSession(Bundle args) {
35         return new MainInteractionSession(this);
36     }
37 
38     public static class MainInteractionSession extends VoiceInteractionSession {
39 
MainInteractionSession(Context context)40         public MainInteractionSession(Context context) {
41             super(context);
42         }
43 
44         @Override
onHandleScreenshot(Bitmap screenshot)45         public void onHandleScreenshot(Bitmap screenshot) {
46             Log.d(TAG, "onHandleScreenshot() called with: screenshot = [" + screenshot + "]");
47             Intent intent = new Intent(ACTION_HANDLE_SCREENSHOT);
48             intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
49             intent.putExtra(KEY_HAS_SCREENSHOT, screenshot != null);
50             getContext().sendBroadcast(intent);
51             finish();
52         }
53     }
54 }