1 /*
2  * Copyright (C) 2023 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 package com.android.systemui.car.distantdisplay.activity;
17 
18 import android.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 
22 /**
23  * Receiver for testing purpose ONLY. This is acting as an entry point for moving the tasks until
24  * UX figure out the specific place to trigger the move ia UI.
25  *
26  * Usage:
27  * When TaskView host is a window in systemUI
28  * Move to DD:
29  * adb shell am broadcast -a com.android.systemui.car.intent.action.MOVE_TASK \
30  * --user 0 --es move "to_dd"
31  * Move from DD:
32  * adb shell am broadcast -a com.android.systemui.car.intent.action.MOVE_TASK \
33  * --user 0 --es move "from_dd"
34  * When TaskView host is a window in systemUI
35  * Move to DD:
36  * adb shell am broadcast -a com.android.systemui.car.intent.action.MOVE_TASK \
37  * --user 10 --es move "to_dd"
38  * Move from DD:
39  * adb shell am broadcast -a com.android.systemui.car.intent.action.MOVE_TASK \
40  * --user 10 --es move "from_dd"
41  *
42  * TODO(b/302548275) : once the CUJs are completed via UX remove this receiver.
43  */
44 public class MoveTaskReceiver extends BroadcastReceiver {
45     public static final String TAG = "MoveTaskReceiver";
46     public static final String MOVE_ACTION = "com.android.systemui.car.intent.action.MOVE_TASK";
47     public static final String MOVE_TO_DISTANT_DISPLAY = "to_dd";
48     public static final String MOVE_TO_DISTANT_DISPLAY_PASSENGER = "to_dd_passenger";
49     public static final String MOVE_FROM_DISTANT_DISPLAY = "from_dd";
50 
51     /**
52      * Called when a request to move the task from one display to another comes in.
53      */
54     public interface Callback {
55         /**
56          * Called when the request to move the task to another display comes in.
57          *
58          * @param movement command which shows the movement direction
59          */
onTaskDisplayChangeRequest(String movement)60         void onTaskDisplayChangeRequest(String movement);
61     }
62 
63     private Callback mOnChangeDisplayForTask;
64 
65     @Override
onReceive(final Context context, final Intent intent)66     public final void onReceive(final Context context, final Intent intent) {
67 
68         if (mOnChangeDisplayForTask == null) {
69             return;
70         }
71         String data = intent.getStringExtra("move");
72 
73         if (data.equals(MOVE_TO_DISTANT_DISPLAY) || data.equals(MOVE_FROM_DISTANT_DISPLAY)
74                 || data.equals(MOVE_TO_DISTANT_DISPLAY_PASSENGER)) {
75             mOnChangeDisplayForTask.onTaskDisplayChangeRequest(data);
76         }
77     }
78 
79     /**
80      * @param listener register's {@link Callback}
81      */
registerOnChangeDisplayForTask(Callback listener)82     public void registerOnChangeDisplayForTask(Callback listener) {
83         mOnChangeDisplayForTask = listener;
84     }
85 
86     /**
87      * Uregister's {@link Callback}
88      */
unRegisterOnChangeDisplayForTask()89     public void unRegisterOnChangeDisplayForTask() {
90         mOnChangeDisplayForTask = null;
91     }
92 }
93