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