blob: f1e801b3a474b846941b08f5c8cece9703188ab5 [file] [log] [blame]
Winson73bc1592016-10-18 18:47:43 -07001/*
2 * Copyright (C) 2016 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
17package com.android.systemui.pip;
18
19import static android.content.pm.PackageManager.FEATURE_LEANBACK_ONLY;
20import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
21
Dave Mankoffa5d8a392019-10-10 12:21:09 -040022import android.content.Context;
Winson73bc1592016-10-18 18:47:43 -070023import android.content.pm.PackageManager;
24import android.content.res.Configuration;
Winson Chung67f5c8b2018-09-24 12:09:19 -070025import android.os.UserHandle;
26import android.os.UserManager;
Gus Prevasab336792018-11-14 13:52:20 -050027
Winson73bc1592016-10-18 18:47:43 -070028import com.android.systemui.SystemUI;
Winson Chungac52f282017-03-30 14:44:52 -070029import com.android.systemui.statusbar.CommandQueue;
Gus Prevasab336792018-11-14 13:52:20 -050030
Winson Chung29a78652017-02-09 18:35:26 -080031import java.io.FileDescriptor;
32import java.io.PrintWriter;
33
Dave Mankoff33174bc2019-10-10 14:57:02 -040034import javax.inject.Inject;
35import javax.inject.Singleton;
36
Winson73bc1592016-10-18 18:47:43 -070037/**
38 * Controls the picture-in-picture window.
39 */
Dave Mankoff33174bc2019-10-10 14:57:02 -040040@Singleton
Winson Chungac52f282017-03-30 14:44:52 -070041public class PipUI extends SystemUI implements CommandQueue.Callbacks {
Winson73bc1592016-10-18 18:47:43 -070042
Winson Chung29a78652017-02-09 18:35:26 -080043 private BasePipManager mPipManager;
44
Winson73bc1592016-10-18 18:47:43 -070045 private boolean mSupportsPip;
Winson73bc1592016-10-18 18:47:43 -070046
Dave Mankoff33174bc2019-10-10 14:57:02 -040047 @Inject
Dave Mankoffa5d8a392019-10-10 12:21:09 -040048 public PipUI(Context context) {
49 super(context);
50 }
51
Winson73bc1592016-10-18 18:47:43 -070052 @Override
53 public void start() {
54 PackageManager pm = mContext.getPackageManager();
55 mSupportsPip = pm.hasSystemFeature(FEATURE_PICTURE_IN_PICTURE);
Winson73bc1592016-10-18 18:47:43 -070056 if (!mSupportsPip) {
57 return;
58 }
Winson Chung29a78652017-02-09 18:35:26 -080059
Winson Chung853c99a2017-03-21 22:16:42 -070060 // Ensure that we are the primary user's SystemUI.
Winson Chung67f5c8b2018-09-24 12:09:19 -070061 final int processUser = UserManager.get(mContext).getUserHandle();
62 if (processUser != UserHandle.USER_SYSTEM) {
Winson Chung853c99a2017-03-21 22:16:42 -070063 throw new IllegalStateException("Non-primary Pip component not currently supported.");
64 }
65
Winson Chung29a78652017-02-09 18:35:26 -080066 mPipManager = pm.hasSystemFeature(FEATURE_LEANBACK_ONLY)
67 ? com.android.systemui.pip.tv.PipManager.getInstance()
68 : com.android.systemui.pip.phone.PipManager.getInstance();
69 mPipManager.initialize(mContext);
Winson Chungac52f282017-03-30 14:44:52 -070070
Jason Monkd7c98552018-12-04 11:14:50 -050071 getComponent(CommandQueue.class).addCallback(this);
Winson Chungac52f282017-03-30 14:44:52 -070072 }
73
74 @Override
75 public void showPictureInPictureMenu() {
76 mPipManager.showPictureInPictureMenu();
Winson73bc1592016-10-18 18:47:43 -070077 }
78
Winson Chung67f5c8b2018-09-24 12:09:19 -070079 public void expandPip() {
Winson Chung2dbcf092018-10-24 13:00:41 -070080 mPipManager.expandPip();
81 }
82
83 public void hidePipMenu(Runnable onStartCallback, Runnable onEndCallback) {
84 mPipManager.hidePipMenu(onStartCallback, onEndCallback);
Winson Chung67f5c8b2018-09-24 12:09:19 -070085 }
86
Winson73bc1592016-10-18 18:47:43 -070087 @Override
88 protected void onConfigurationChanged(Configuration newConfig) {
89 super.onConfigurationChanged(newConfig);
Winson Chung29a78652017-02-09 18:35:26 -080090 if (mPipManager == null) {
Winson73bc1592016-10-18 18:47:43 -070091 return;
92 }
Winson Chung29a78652017-02-09 18:35:26 -080093
Winson Chung0c5a5922017-05-22 17:41:06 -070094 mPipManager.onConfigurationChanged(newConfig);
Winson Chung29a78652017-02-09 18:35:26 -080095 }
96
Hongwei Wang9b751802019-09-11 12:13:21 -070097 public void setShelfHeight(boolean visible, int height) {
98 if (mPipManager == null) {
99 return;
100 }
101
102 mPipManager.setShelfHeight(visible, height);
103 }
104
Winson Chung29a78652017-02-09 18:35:26 -0800105 @Override
106 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
107 if (mPipManager == null) {
108 return;
Winson73bc1592016-10-18 18:47:43 -0700109 }
Winson Chung29a78652017-02-09 18:35:26 -0800110
111 mPipManager.dump(pw);
Winson73bc1592016-10-18 18:47:43 -0700112 }
113}