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