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 
17 package android.app.cts.wallpapers;
18 
19 import android.app.Activity;
20 import android.app.WallpaperManager;
21 import android.content.Context;
22 import android.graphics.Color;
23 import android.os.Bundle;
24 import android.os.IBinder;
25 import android.view.Window;
26 import android.widget.FrameLayout;
27 
28 import javax.annotation.Nullable;
29 
30 /* This activity is added to simulate switching window focus by
31 * launching a second app on top of the first activity
32 */
33 public class WallpaperOverlayTestActivity extends Activity {
34     Context mContext;
35     WallpaperManager mWallpaperManager;
36 
37     @Override
onCreate(@ullable Bundle savedInstanceState)38     protected void onCreate(@Nullable Bundle savedInstanceState) {
39         super.onCreate(savedInstanceState);
40         mContext = this.getApplicationContext();
41         mWallpaperManager = WallpaperManager.getInstance(mContext);
42         FrameLayout frameLayout = new FrameLayout(this);
43         frameLayout.setBackgroundColor(Color.TRANSPARENT);
44         FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
45                 FrameLayout.LayoutParams.MATCH_PARENT,
46                 FrameLayout.LayoutParams.MATCH_PARENT);
47 
48         setContentView(frameLayout, layoutParams);
49     }
50 
sendWallpaperCommand(String command)51     public void sendWallpaperCommand(String command) {
52         Window window = this.getWindow();
53         IBinder windowToken = window.getDecorView().getWindowToken();
54         mWallpaperManager.sendWallpaperCommand(
55                 windowToken, WallpaperManager.COMMAND_TAP, 50, 50, 0, null);
56     }
57 }
58