blob: 37c8163702cf0c48aa8e6089d72255b2ff2d3a44 [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
22import android.content.pm.PackageManager;
23import android.content.res.Configuration;
Winson Chung67f5c8b2018-09-24 12:09:19 -070024import android.os.UserHandle;
25import android.os.UserManager;
Gus Prevasab336792018-11-14 13:52:20 -050026
Winson73bc1592016-10-18 18:47:43 -070027import com.android.systemui.SystemUI;
Winson Chungac52f282017-03-30 14:44:52 -070028import com.android.systemui.statusbar.CommandQueue;
Gus Prevasab336792018-11-14 13:52:20 -050029
Winson Chung29a78652017-02-09 18:35:26 -080030import java.io.FileDescriptor;
31import java.io.PrintWriter;
32
Winson73bc1592016-10-18 18:47:43 -070033/**
34 * Controls the picture-in-picture window.
35 */
Winson Chungac52f282017-03-30 14:44:52 -070036public class PipUI extends SystemUI implements CommandQueue.Callbacks {
Winson73bc1592016-10-18 18:47:43 -070037
Winson Chung29a78652017-02-09 18:35:26 -080038 private BasePipManager mPipManager;
39
Winson73bc1592016-10-18 18:47:43 -070040 private boolean mSupportsPip;
Winson73bc1592016-10-18 18:47:43 -070041
42 @Override
43 public void start() {
44 PackageManager pm = mContext.getPackageManager();
45 mSupportsPip = pm.hasSystemFeature(FEATURE_PICTURE_IN_PICTURE);
Winson73bc1592016-10-18 18:47:43 -070046 if (!mSupportsPip) {
47 return;
48 }
Winson Chung29a78652017-02-09 18:35:26 -080049
Winson Chung853c99a2017-03-21 22:16:42 -070050 // Ensure that we are the primary user's SystemUI.
Winson Chung67f5c8b2018-09-24 12:09:19 -070051 final int processUser = UserManager.get(mContext).getUserHandle();
52 if (processUser != UserHandle.USER_SYSTEM) {
Winson Chung853c99a2017-03-21 22:16:42 -070053 throw new IllegalStateException("Non-primary Pip component not currently supported.");
54 }
55
Winson Chung29a78652017-02-09 18:35:26 -080056 mPipManager = pm.hasSystemFeature(FEATURE_LEANBACK_ONLY)
57 ? com.android.systemui.pip.tv.PipManager.getInstance()
58 : com.android.systemui.pip.phone.PipManager.getInstance();
59 mPipManager.initialize(mContext);
Winson Chungac52f282017-03-30 14:44:52 -070060
Jason Monkd7c98552018-12-04 11:14:50 -050061 getComponent(CommandQueue.class).addCallback(this);
Winson Chung67f5c8b2018-09-24 12:09:19 -070062 putComponent(PipUI.class, this);
Winson Chungac52f282017-03-30 14:44:52 -070063 }
64
65 @Override
66 public void showPictureInPictureMenu() {
67 mPipManager.showPictureInPictureMenu();
Winson73bc1592016-10-18 18:47:43 -070068 }
69
Winson Chung67f5c8b2018-09-24 12:09:19 -070070 public void expandPip() {
Winson Chung2dbcf092018-10-24 13:00:41 -070071 mPipManager.expandPip();
72 }
73
74 public void hidePipMenu(Runnable onStartCallback, Runnable onEndCallback) {
75 mPipManager.hidePipMenu(onStartCallback, onEndCallback);
Winson Chung67f5c8b2018-09-24 12:09:19 -070076 }
77
Winson73bc1592016-10-18 18:47:43 -070078 @Override
79 protected void onConfigurationChanged(Configuration newConfig) {
80 super.onConfigurationChanged(newConfig);
Winson Chung29a78652017-02-09 18:35:26 -080081 if (mPipManager == null) {
Winson73bc1592016-10-18 18:47:43 -070082 return;
83 }
Winson Chung29a78652017-02-09 18:35:26 -080084
Winson Chung0c5a5922017-05-22 17:41:06 -070085 mPipManager.onConfigurationChanged(newConfig);
Winson Chung29a78652017-02-09 18:35:26 -080086 }
87
88 @Override
89 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
90 if (mPipManager == null) {
91 return;
Winson73bc1592016-10-18 18:47:43 -070092 }
Winson Chung29a78652017-02-09 18:35:26 -080093
94 mPipManager.dump(pw);
Winson73bc1592016-10-18 18:47:43 -070095 }
96}