Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.pip; |
| 18 | |
| 19 | import static android.content.pm.PackageManager.FEATURE_LEANBACK_ONLY; |
| 20 | import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE; |
| 21 | |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame] | 22 | import android.content.Context; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 23 | import android.content.pm.PackageManager; |
| 24 | import android.content.res.Configuration; |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 25 | import android.os.UserHandle; |
| 26 | import android.os.UserManager; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 27 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 28 | import com.android.systemui.SystemUI; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 29 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 30 | import com.android.systemui.statusbar.CommandQueue; |
Hongwei Wang | ebf1808 | 2019-09-26 14:25:11 -0700 | [diff] [blame] | 31 | import com.android.systemui.wm.DisplayWindowController; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 32 | |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 33 | import java.io.FileDescriptor; |
| 34 | import java.io.PrintWriter; |
| 35 | |
Dave Mankoff | 33174bc | 2019-10-10 14:57:02 -0400 | [diff] [blame] | 36 | import javax.inject.Inject; |
| 37 | import javax.inject.Singleton; |
| 38 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 39 | /** |
| 40 | * Controls the picture-in-picture window. |
| 41 | */ |
Dave Mankoff | 33174bc | 2019-10-10 14:57:02 -0400 | [diff] [blame] | 42 | @Singleton |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 43 | public class PipUI extends SystemUI implements CommandQueue.Callbacks { |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 44 | |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 45 | private final CommandQueue mCommandQueue; |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 46 | private BasePipManager mPipManager; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 47 | private final BroadcastDispatcher mBroadcastDispatcher; |
Hongwei Wang | ebf1808 | 2019-09-26 14:25:11 -0700 | [diff] [blame] | 48 | private final DisplayWindowController mDisplayWindowController; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 49 | private boolean mSupportsPip; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 50 | |
Dave Mankoff | 33174bc | 2019-10-10 14:57:02 -0400 | [diff] [blame] | 51 | @Inject |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 52 | public PipUI(Context context, CommandQueue commandQueue, |
Hongwei Wang | ebf1808 | 2019-09-26 14:25:11 -0700 | [diff] [blame] | 53 | BroadcastDispatcher broadcastDispatcher, |
| 54 | DisplayWindowController displayWindowController) { |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame] | 55 | super(context); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 56 | mBroadcastDispatcher = broadcastDispatcher; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 57 | mCommandQueue = commandQueue; |
Hongwei Wang | ebf1808 | 2019-09-26 14:25:11 -0700 | [diff] [blame] | 58 | mDisplayWindowController = displayWindowController; |
Dave Mankoff | a5d8a39 | 2019-10-10 12:21:09 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 61 | @Override |
| 62 | public void start() { |
| 63 | PackageManager pm = mContext.getPackageManager(); |
| 64 | mSupportsPip = pm.hasSystemFeature(FEATURE_PICTURE_IN_PICTURE); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 65 | if (!mSupportsPip) { |
| 66 | return; |
| 67 | } |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 68 | |
Winson Chung | 853c99a | 2017-03-21 22:16:42 -0700 | [diff] [blame] | 69 | // Ensure that we are the primary user's SystemUI. |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 70 | final int processUser = UserManager.get(mContext).getUserHandle(); |
| 71 | if (processUser != UserHandle.USER_SYSTEM) { |
Winson Chung | 853c99a | 2017-03-21 22:16:42 -0700 | [diff] [blame] | 72 | throw new IllegalStateException("Non-primary Pip component not currently supported."); |
| 73 | } |
| 74 | |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 75 | mPipManager = pm.hasSystemFeature(FEATURE_LEANBACK_ONLY) |
| 76 | ? com.android.systemui.pip.tv.PipManager.getInstance() |
| 77 | : com.android.systemui.pip.phone.PipManager.getInstance(); |
Hongwei Wang | ebf1808 | 2019-09-26 14:25:11 -0700 | [diff] [blame] | 78 | mPipManager.initialize(mContext, mBroadcastDispatcher, mDisplayWindowController); |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 79 | |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 80 | mCommandQueue.addCallback(this); |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public void showPictureInPictureMenu() { |
| 85 | mPipManager.showPictureInPictureMenu(); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 88 | public void expandPip() { |
Winson Chung | 2dbcf09 | 2018-10-24 13:00:41 -0700 | [diff] [blame] | 89 | mPipManager.expandPip(); |
| 90 | } |
| 91 | |
| 92 | public void hidePipMenu(Runnable onStartCallback, Runnable onEndCallback) { |
| 93 | mPipManager.hidePipMenu(onStartCallback, onEndCallback); |
Winson Chung | 67f5c8b | 2018-09-24 12:09:19 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 96 | @Override |
| 97 | protected void onConfigurationChanged(Configuration newConfig) { |
| 98 | super.onConfigurationChanged(newConfig); |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 99 | if (mPipManager == null) { |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 100 | return; |
| 101 | } |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 102 | |
Winson Chung | 0c5a592 | 2017-05-22 17:41:06 -0700 | [diff] [blame] | 103 | mPipManager.onConfigurationChanged(newConfig); |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Hongwei Wang | 9b75180 | 2019-09-11 12:13:21 -0700 | [diff] [blame] | 106 | public void setShelfHeight(boolean visible, int height) { |
| 107 | if (mPipManager == null) { |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | mPipManager.setShelfHeight(visible, height); |
| 112 | } |
| 113 | |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 114 | @Override |
| 115 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 116 | if (mPipManager == null) { |
| 117 | return; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 118 | } |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 119 | |
| 120 | mPipManager.dump(pw); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 121 | } |
| 122 | } |