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; |
| 24 | |
| 25 | import com.android.systemui.SystemUI; |
Winson Chung | 853c99a | 2017-03-21 22:16:42 -0700 | [diff] [blame] | 26 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 27 | import com.android.systemui.statusbar.CommandQueue; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 28 | |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 29 | import java.io.FileDescriptor; |
| 30 | import java.io.PrintWriter; |
| 31 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Controls the picture-in-picture window. |
| 34 | */ |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 35 | public class PipUI extends SystemUI implements CommandQueue.Callbacks { |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 36 | |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 37 | private BasePipManager mPipManager; |
| 38 | |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 39 | private boolean mSupportsPip; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 40 | |
| 41 | @Override |
| 42 | public void start() { |
| 43 | PackageManager pm = mContext.getPackageManager(); |
| 44 | mSupportsPip = pm.hasSystemFeature(FEATURE_PICTURE_IN_PICTURE); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 45 | if (!mSupportsPip) { |
| 46 | return; |
| 47 | } |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 48 | |
Winson Chung | 853c99a | 2017-03-21 22:16:42 -0700 | [diff] [blame] | 49 | // Ensure that we are the primary user's SystemUI. |
| 50 | final int processUser = SystemServicesProxy.getInstance(mContext).getProcessUser(); |
| 51 | if (!SystemServicesProxy.getInstance(mContext).isSystemUser(processUser)) { |
| 52 | throw new IllegalStateException("Non-primary Pip component not currently supported."); |
| 53 | } |
| 54 | |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 55 | mPipManager = pm.hasSystemFeature(FEATURE_LEANBACK_ONLY) |
| 56 | ? com.android.systemui.pip.tv.PipManager.getInstance() |
| 57 | : com.android.systemui.pip.phone.PipManager.getInstance(); |
| 58 | mPipManager.initialize(mContext); |
Winson Chung | ac52f28 | 2017-03-30 14:44:52 -0700 | [diff] [blame] | 59 | |
| 60 | getComponent(CommandQueue.class).addCallbacks(this); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public void showPictureInPictureMenu() { |
| 65 | mPipManager.showPictureInPictureMenu(); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
| 69 | protected void onConfigurationChanged(Configuration newConfig) { |
| 70 | super.onConfigurationChanged(newConfig); |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 71 | if (mPipManager == null) { |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 72 | return; |
| 73 | } |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 74 | |
Winson Chung | 0c5a592 | 2017-05-22 17:41:06 -0700 | [diff] [blame] | 75 | mPipManager.onConfigurationChanged(newConfig); |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 80 | if (mPipManager == null) { |
| 81 | return; |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 82 | } |
Winson Chung | 29a7865 | 2017-02-09 18:35:26 -0800 | [diff] [blame] | 83 | |
| 84 | mPipManager.dump(pw); |
Winson | 73bc159 | 2016-10-18 18:47:43 -0700 | [diff] [blame] | 85 | } |
| 86 | } |