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