blob: b7164cbb327162a6ae030f4d7f036b2ddf219770 [file] [log] [blame]
Winson73bc1592016-10-18 18:47:43 -07001/*
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
17package com.android.systemui.pip;
18
19import static android.content.pm.PackageManager.FEATURE_LEANBACK_ONLY;
20import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
21
22import android.content.pm.PackageManager;
23import android.content.res.Configuration;
24
25import com.android.systemui.SystemUI;
Winson Chung853c99a2017-03-21 22:16:42 -070026import com.android.systemui.recents.misc.SystemServicesProxy;
Winson Chungac52f282017-03-30 14:44:52 -070027import com.android.systemui.statusbar.CommandQueue;
Winson73bc1592016-10-18 18:47:43 -070028
Winson Chung29a78652017-02-09 18:35:26 -080029import java.io.FileDescriptor;
30import java.io.PrintWriter;
31
Winson73bc1592016-10-18 18:47:43 -070032/**
33 * Controls the picture-in-picture window.
34 */
Winson Chungac52f282017-03-30 14:44:52 -070035public class PipUI extends SystemUI implements CommandQueue.Callbacks {
Winson73bc1592016-10-18 18:47:43 -070036
Winson Chung29a78652017-02-09 18:35:26 -080037 private BasePipManager mPipManager;
38
Winson73bc1592016-10-18 18:47:43 -070039 private boolean mSupportsPip;
Winson73bc1592016-10-18 18:47:43 -070040
41 @Override
42 public void start() {
43 PackageManager pm = mContext.getPackageManager();
44 mSupportsPip = pm.hasSystemFeature(FEATURE_PICTURE_IN_PICTURE);
Winson73bc1592016-10-18 18:47:43 -070045 if (!mSupportsPip) {
46 return;
47 }
Winson Chung29a78652017-02-09 18:35:26 -080048
Winson Chung853c99a2017-03-21 22:16:42 -070049 // 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 Chung29a78652017-02-09 18:35:26 -080055 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 Chungac52f282017-03-30 14:44:52 -070059
60 getComponent(CommandQueue.class).addCallbacks(this);
61 }
62
63 @Override
64 public void showPictureInPictureMenu() {
65 mPipManager.showPictureInPictureMenu();
Winson73bc1592016-10-18 18:47:43 -070066 }
67
68 @Override
69 protected void onConfigurationChanged(Configuration newConfig) {
70 super.onConfigurationChanged(newConfig);
Winson Chung29a78652017-02-09 18:35:26 -080071 if (mPipManager == null) {
Winson73bc1592016-10-18 18:47:43 -070072 return;
73 }
Winson Chung29a78652017-02-09 18:35:26 -080074
Winson Chung0c5a5922017-05-22 17:41:06 -070075 mPipManager.onConfigurationChanged(newConfig);
Winson Chung29a78652017-02-09 18:35:26 -080076 }
77
78 @Override
79 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
80 if (mPipManager == null) {
81 return;
Winson73bc1592016-10-18 18:47:43 -070082 }
Winson Chung29a78652017-02-09 18:35:26 -080083
84 mPipManager.dump(pw);
Winson73bc1592016-10-18 18:47:43 -070085 }
86}