1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.android.launcher3.testcomponent;
17 
18 import android.app.Instrumentation;
19 import android.net.Uri;
20 import android.os.Bundle;
21 
22 import androidx.test.InstrumentationRegistry;
23 
24 /**
25  * Content provider to receive commands from tests
26  */
27 public class TestCommandReceiver {
28 
29     public static final String ENABLE_TEST_LAUNCHER = "enable-test-launcher";
30     public static final String DISABLE_TEST_LAUNCHER = "disable-test-launcher";
31     public static final String KILL_PROCESS = "kill-process";
32     public static final String GET_SYSTEM_HEALTH_MESSAGE = "get-system-health-message";
33     public static final String SET_LIST_VIEW_SERVICE_BINDER = "set-list-view-service-binder";
34 
35     public static final String EXTRA_VALUE = "value";
36 
callCommand(String command)37     public static Bundle callCommand(String command) {
38         return callCommand(command, null);
39     }
40 
callCommand(String command, String arg)41     public static Bundle callCommand(String command, String arg) {
42         return callCommand(command, arg, null);
43     }
44 
callCommand(String command, String arg, Bundle extras)45     public static Bundle callCommand(String command, String arg, Bundle extras) {
46         Instrumentation inst = InstrumentationRegistry.getInstrumentation();
47         Uri uri = Uri.parse("content://" + inst.getContext().getPackageName() + ".commands");
48         return inst.getTargetContext().getContentResolver().call(uri, command, arg, extras);
49     }
50 }
51