Adding settings for managing auto-enter picture-in-picture.
- Add per-app setting for users to control whether an app can enter picture-in-picture when it is hidden. Bug: 34520451 Test: make -j40 RunSettingsRoboTests Change-Id: I182d6069ad01e42f1d3d6623ea21362ce802efba Signed-off-by: Winson Chung <winsonc@google.com>
This commit is contained in:
@@ -2574,6 +2574,20 @@
|
|||||||
android:value="com.android.settings.applications.VrListenerSettings" />
|
android:value="com.android.settings.applications.VrListenerSettings" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name="Settings$PictureInPictureSettingsActivity"
|
||||||
|
android:label="@string/picture_in_picture_title"
|
||||||
|
android:taskAffinity="">
|
||||||
|
<intent-filter android:priority="1">
|
||||||
|
<action android:name="android.settings.PICTURE_IN_PICTURE_SETTINGS" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||||
|
android:value="com.android.settings.applications.PictureInPictureSettings" />
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity android:name="Settings$ZenAccessSettingsActivity"
|
<activity android:name="Settings$ZenAccessSettingsActivity"
|
||||||
android:label="@string/manage_zen_access_title"
|
android:label="@string/manage_zen_access_title"
|
||||||
|
@@ -6317,6 +6317,21 @@
|
|||||||
flicker while in VR mode. -->
|
flicker while in VR mode. -->
|
||||||
<string name="display_vr_pref_off">Reduce flicker</string>
|
<string name="display_vr_pref_off">Reduce flicker</string>
|
||||||
|
|
||||||
|
<!-- Special access > Title for managing Picture-in-picture settings. [CHAR LIMIT=50] -->
|
||||||
|
<string name="picture_in_picture_title">Picture-in-picture</string>
|
||||||
|
|
||||||
|
<!-- Special access > Picture-in-picture > Text to display when the list is empty. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="picture_in_picture_empty_text">No installed apps support Picture-in-picture</string>
|
||||||
|
|
||||||
|
<!-- Special access > Picture-in-picture > Additional keywords to search for. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="picture_in_picture_keywords">pip picture in</string>
|
||||||
|
|
||||||
|
<!-- Apps > App Details > Advanced section string title. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="picture_in_picture_app_detail_title">Picture-in-picture</string>
|
||||||
|
|
||||||
|
<!-- Apps > App Details > Advanced section string description. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="picture_in_picture_app_detail_summary">Permit entering picture-in-picture when leaving app</string>
|
||||||
|
|
||||||
<!-- Sound & notification > Advanced section: Title for managing Do Not Disturb access option. [CHAR LIMIT=40] -->
|
<!-- Sound & notification > Advanced section: Title for managing Do Not Disturb access option. [CHAR LIMIT=40] -->
|
||||||
<string name="manage_zen_access_title">Do Not Disturb access</string>
|
<string name="manage_zen_access_title">Do Not Disturb access</string>
|
||||||
|
|
||||||
|
@@ -73,6 +73,11 @@
|
|||||||
android:title="@string/manage_notification_access_title"
|
android:title="@string/manage_notification_access_title"
|
||||||
android:fragment="com.android.settings.notification.NotificationAccessSettings" />
|
android:fragment="com.android.settings.notification.NotificationAccessSettings" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="picture_in_picture"
|
||||||
|
android:title="@string/picture_in_picture_title"
|
||||||
|
android:fragment="com.android.settings.applications.PictureInPictureSettings"
|
||||||
|
settings:keywords="@string/picture_in_picture_keywords" />
|
||||||
<Preference
|
<Preference
|
||||||
android:key="premium_sms"
|
android:key="premium_sms"
|
||||||
android:title="@string/premium_sms_access"
|
android:title="@string/premium_sms_access"
|
||||||
|
@@ -105,6 +105,7 @@ public class Settings extends SettingsActivity {
|
|||||||
public static class UserSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class UserSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class NotificationAccessSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class NotificationAccessSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class VrListenersSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class VrListenersSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
|
public static class PictureInPictureSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ZenAccessSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ZenAccessSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ConditionProviderSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ConditionProviderSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class UsbSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class UsbSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
|
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.applications;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface replicates a subset of the android.content.pm.ActivityInfo. The interface
|
||||||
|
* exists so that we can use a thin wrapper around the ActivityInfo in production code and a mock in
|
||||||
|
* tests.
|
||||||
|
*/
|
||||||
|
public interface ActivityInfoWrapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the resizeMode of the activity.
|
||||||
|
*/
|
||||||
|
int getResizeMode();
|
||||||
|
}
|
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.applications;
|
||||||
|
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
|
||||||
|
public class ActivityInfoWrapperImpl implements ActivityInfoWrapper {
|
||||||
|
|
||||||
|
private final ActivityInfo mInfo;
|
||||||
|
|
||||||
|
public ActivityInfoWrapperImpl(ActivityInfo info) {
|
||||||
|
mInfo = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getResizeMode() {
|
||||||
|
return mInfo.resizeMode;
|
||||||
|
}
|
||||||
|
}
|
@@ -21,8 +21,6 @@ import android.app.Activity;
|
|||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.LoaderManager.LoaderCallbacks;
|
import android.app.LoaderManager.LoaderCallbacks;
|
||||||
import android.app.Notification;
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
@@ -52,9 +50,8 @@ import android.os.RemoteException;
|
|||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.service.notification.NotificationListenerService.Ranking;
|
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.support.v7.preference.PreferenceCategory;
|
import android.support.v7.preference.PreferenceCategory;
|
||||||
@@ -78,7 +75,6 @@ import android.widget.TextView;
|
|||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.internal.os.BatterySipper;
|
import com.android.internal.os.BatterySipper;
|
||||||
import com.android.internal.os.BatteryStatsHelper;
|
import com.android.internal.os.BatteryStatsHelper;
|
||||||
import com.android.internal.widget.LockPatternUtils;
|
|
||||||
import com.android.settings.AppHeader;
|
import com.android.settings.AppHeader;
|
||||||
import com.android.settings.DeviceAdminAdd;
|
import com.android.settings.DeviceAdminAdd;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -933,9 +929,23 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
AdvancedAppSettings.class, "default_sms_app", R.string.sms_application_title,
|
AdvancedAppSettings.class, "default_sms_app", R.string.sms_application_title,
|
||||||
R.string.configure_apps));
|
R.string.configure_apps));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the package info with the activities
|
||||||
|
PackageInfo packageInfoWithActivities = null;
|
||||||
|
try {
|
||||||
|
packageInfoWithActivities = mPm.getPackageInfoAsUser(mPackageName,
|
||||||
|
PackageManager.GET_ACTIVITIES, UserHandle.myUserId());
|
||||||
|
} catch (NameNotFoundException e) {
|
||||||
|
Log.e(TAG, "Exception while retrieving the package info of " + mPackageName, e);
|
||||||
|
}
|
||||||
|
|
||||||
boolean hasDrawOverOtherApps = hasPermission(permission.SYSTEM_ALERT_WINDOW);
|
boolean hasDrawOverOtherApps = hasPermission(permission.SYSTEM_ALERT_WINDOW);
|
||||||
boolean hasWriteSettings = hasPermission(permission.WRITE_SETTINGS);
|
boolean hasWriteSettings = hasPermission(permission.WRITE_SETTINGS);
|
||||||
if (hasDrawOverOtherApps || hasWriteSettings) {
|
boolean hasPictureInPictureActivities = (packageInfoWithActivities != null) &&
|
||||||
|
PictureInPictureSettings.checkPackageHasPictureInPictureActivities(
|
||||||
|
packageInfoWithActivities.packageName,
|
||||||
|
packageInfoWithActivities.activities);
|
||||||
|
if (hasDrawOverOtherApps || hasWriteSettings || hasPictureInPictureActivities) {
|
||||||
PreferenceCategory category = new PreferenceCategory(getPrefContext());
|
PreferenceCategory category = new PreferenceCategory(getPrefContext());
|
||||||
category.setTitle(R.string.advanced_apps);
|
category.setTitle(R.string.advanced_apps);
|
||||||
screen.addPreference(category);
|
screen.addPreference(category);
|
||||||
@@ -968,6 +978,23 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
});
|
});
|
||||||
category.addPreference(pref);
|
category.addPreference(pref);
|
||||||
}
|
}
|
||||||
|
if (hasPictureInPictureActivities) {
|
||||||
|
final SwitchPreference pref = new SwitchPreference(getPrefContext());
|
||||||
|
pref.setPersistent(false);
|
||||||
|
pref.setTitle(R.string.picture_in_picture_app_detail_title);
|
||||||
|
pref.setSummary(R.string.picture_in_picture_app_detail_summary);
|
||||||
|
pref.setChecked(PictureInPictureSettings.getEnterPipOnHideStateForPackage(
|
||||||
|
getContext(), mPackageInfo.applicationInfo.uid, mPackageName));
|
||||||
|
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
PictureInPictureSettings.setEnterPipOnHideStateForPackage(getContext(),
|
||||||
|
mPackageInfo.applicationInfo.uid, mPackageName, (Boolean) newValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
category.addPreference(pref);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addAppInstallerInfoPref(screen);
|
addAppInstallerInfoPref(screen);
|
||||||
|
@@ -0,0 +1,201 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.android.settings.applications;
|
||||||
|
|
||||||
|
import static android.app.AppOpsManager.MODE_ALLOWED;
|
||||||
|
import static android.app.AppOpsManager.MODE_ERRORED;
|
||||||
|
import static android.app.AppOpsManager.OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE;
|
||||||
|
import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
|
||||||
|
import static android.content.pm.PackageManager.GET_ACTIVITIES;
|
||||||
|
|
||||||
|
import android.annotation.Nullable;
|
||||||
|
import android.app.AppOpsManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.content.pm.PackageItemInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.support.v14.preference.SwitchPreference;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
import android.util.ArrayMap;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.notification.EmptyTextSettings;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PictureInPictureSettings extends EmptyTextSettings {
|
||||||
|
|
||||||
|
private static final String TAG = PictureInPictureSettings.class.getSimpleName();
|
||||||
|
@VisibleForTesting
|
||||||
|
static final List<String> IGNORE_PACKAGE_LIST = new ArrayList<>();
|
||||||
|
static {
|
||||||
|
IGNORE_PACKAGE_LIST.add("com.android.systemui");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private PackageManager mPackageManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the package has any activities that declare that they support
|
||||||
|
* picture-in-picture.
|
||||||
|
*/
|
||||||
|
static boolean checkPackageHasPictureInPictureActivities(String packageName,
|
||||||
|
ActivityInfo[] activities) {
|
||||||
|
ActivityInfoWrapper[] wrappedActivities = null;
|
||||||
|
if (activities != null) {
|
||||||
|
wrappedActivities = new ActivityInfoWrapper[activities.length];
|
||||||
|
for (int i = 0; i < activities.length; i++) {
|
||||||
|
wrappedActivities[i] = new ActivityInfoWrapperImpl(activities[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return checkPackageHasPictureInPictureActivities(packageName, wrappedActivities);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the package has any activities that declare that they support
|
||||||
|
* picture-in-picture.
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
static boolean checkPackageHasPictureInPictureActivities(String packageName,
|
||||||
|
ActivityInfoWrapper[] activities) {
|
||||||
|
// Skip if it's in the ignored list
|
||||||
|
if (IGNORE_PACKAGE_LIST.contains(packageName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate through all the activities and check if it is resizeable and supports
|
||||||
|
// picture-in-picture
|
||||||
|
if (activities != null) {
|
||||||
|
for (int i = activities.length - 1; i >= 0; i--) {
|
||||||
|
if (activities[i].getResizeMode() == RESIZE_MODE_RESIZEABLE_AND_PIPABLE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the app associated with the given {@param packageName} is allowed to enter
|
||||||
|
* picture-in-picture when it is hidden.
|
||||||
|
*/
|
||||||
|
static void setEnterPipOnHideStateForPackage(Context context, int uid, String packageName,
|
||||||
|
boolean value) {
|
||||||
|
final AppOpsManager appOps = context.getSystemService(AppOpsManager.class);
|
||||||
|
final int newMode = value ? MODE_ALLOWED : MODE_ERRORED;
|
||||||
|
appOps.setMode(OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE,
|
||||||
|
uid, packageName, newMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether the app associated with the given {@param packageName} is allowed to enter
|
||||||
|
* picture-in-picture when it is hidden.
|
||||||
|
*/
|
||||||
|
static boolean getEnterPipOnHideStateForPackage(Context context, int uid, String packageName) {
|
||||||
|
final AppOpsManager appOps = context.getSystemService(AppOpsManager.class);
|
||||||
|
return appOps.checkOpNoThrow(OP_ENTER_PICTURE_IN_PICTURE_ON_HIDE,
|
||||||
|
uid, packageName) == MODE_ALLOWED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle icicle) {
|
||||||
|
super.onCreate(icicle);
|
||||||
|
|
||||||
|
mContext = getActivity();
|
||||||
|
mPackageManager = mContext.getPackageManager();
|
||||||
|
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(mContext));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
// Clear the prefs
|
||||||
|
final PreferenceScreen screen = getPreferenceScreen();
|
||||||
|
screen.removeAll();
|
||||||
|
|
||||||
|
// Fetch the set of applications which have at least one activity that declare that they
|
||||||
|
// support picture-in-picture
|
||||||
|
final ArrayMap<String, Boolean> packageToState = new ArrayMap<>();
|
||||||
|
final ArrayList<ApplicationInfo> pipApps = new ArrayList<>();
|
||||||
|
final List<PackageInfo> installedPackages = mPackageManager.getInstalledPackagesAsUser(
|
||||||
|
GET_ACTIVITIES, UserHandle.myUserId());
|
||||||
|
for (PackageInfo packageInfo : installedPackages) {
|
||||||
|
if (checkPackageHasPictureInPictureActivities(packageInfo.packageName,
|
||||||
|
packageInfo.activities)) {
|
||||||
|
final String packageName = packageInfo.applicationInfo.packageName;
|
||||||
|
final boolean state = getEnterPipOnHideStateForPackage(mContext,
|
||||||
|
packageInfo.applicationInfo.uid, packageName);
|
||||||
|
pipApps.add(packageInfo.applicationInfo);
|
||||||
|
packageToState.put(packageName, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(pipApps, new PackageItemInfo.DisplayNameComparator(mPackageManager));
|
||||||
|
|
||||||
|
// Rebuild the list of prefs
|
||||||
|
final Context prefContext = getPrefContext();
|
||||||
|
for (final ApplicationInfo appInfo : pipApps) {
|
||||||
|
final String packageName = appInfo.packageName;
|
||||||
|
final CharSequence label = appInfo.loadLabel(mPackageManager);
|
||||||
|
final SwitchPreference pref = new SwitchPreference(prefContext);
|
||||||
|
pref.setPersistent(false);
|
||||||
|
pref.setIcon(appInfo.loadIcon(mPackageManager));
|
||||||
|
pref.setTitle(label);
|
||||||
|
pref.setChecked(packageToState.get(packageName));
|
||||||
|
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
logSpecialPermissionChange((Boolean) newValue, packageName);
|
||||||
|
setEnterPipOnHideStateForPackage(mContext, appInfo.uid, packageName,
|
||||||
|
(Boolean) newValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
screen.addPreference(pref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
setEmptyText(R.string.picture_in_picture_empty_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return MetricsEvent.SETTINGS_MANAGE_PICTURE_IN_PICTURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void logSpecialPermissionChange(boolean newState, String packageName) {
|
||||||
|
int logCategory = newState
|
||||||
|
? MetricsEvent.APP_PICTURE_IN_PICTURE_ON_HIDE_ALLOW
|
||||||
|
: MetricsEvent.APP_PICTURE_IN_PICTURE_ON_HIDE_DENY;
|
||||||
|
FeatureFactory.getFactory(getContext())
|
||||||
|
.getMetricsFeatureProvider().action(getContext(), logCategory, packageName);
|
||||||
|
}
|
||||||
|
}
|
@@ -57,6 +57,7 @@ import com.android.settings.applications.ManageApplications;
|
|||||||
import com.android.settings.applications.ManageAssist;
|
import com.android.settings.applications.ManageAssist;
|
||||||
import com.android.settings.applications.ManageDomainUrls;
|
import com.android.settings.applications.ManageDomainUrls;
|
||||||
import com.android.settings.applications.NotificationApps;
|
import com.android.settings.applications.NotificationApps;
|
||||||
|
import com.android.settings.applications.PictureInPictureSettings;
|
||||||
import com.android.settings.applications.ProcessStatsSummary;
|
import com.android.settings.applications.ProcessStatsSummary;
|
||||||
import com.android.settings.applications.ProcessStatsUi;
|
import com.android.settings.applications.ProcessStatsUi;
|
||||||
import com.android.settings.applications.UsageAccessDetails;
|
import com.android.settings.applications.UsageAccessDetails;
|
||||||
@@ -225,6 +226,7 @@ public class SettingsGateway {
|
|||||||
AdvancedAppSettings.class.getName(),
|
AdvancedAppSettings.class.getName(),
|
||||||
WallpaperTypeSettings.class.getName(),
|
WallpaperTypeSettings.class.getName(),
|
||||||
VrListenerSettings.class.getName(),
|
VrListenerSettings.class.getName(),
|
||||||
|
PictureInPictureSettings.class.getName(),
|
||||||
ManagedProfileSettings.class.getName(),
|
ManagedProfileSettings.class.getName(),
|
||||||
ChooseAccountActivity.class.getName(),
|
ChooseAccountActivity.class.getName(),
|
||||||
IccLockSettings.class.getName(),
|
IccLockSettings.class.getName(),
|
||||||
|
@@ -91,3 +91,4 @@ com.android.settings.applications.ConvertToFbe
|
|||||||
com.android.settings.localepicker.LocaleListEditor
|
com.android.settings.localepicker.LocaleListEditor
|
||||||
com.android.settings.qstile.DevelopmentTileConfigActivity$DevelopmentTileConfigFragment
|
com.android.settings.qstile.DevelopmentTileConfigActivity$DevelopmentTileConfigFragment
|
||||||
com.android.settings.applications.ExternalSourcesDetails
|
com.android.settings.applications.ExternalSourcesDetails
|
||||||
|
com.android.settings.applications.PictureInPictureSettings
|
||||||
|
@@ -0,0 +1,132 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.applications;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
|
||||||
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Answers;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
import static org.mockito.Matchers.argThat;
|
||||||
|
import static org.mockito.Matchers.anyObject;
|
||||||
|
import static org.mockito.Matchers.eq;
|
||||||
|
import static org.mockito.Mockito.atLeast;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class PictureInPictureSettingsTest {
|
||||||
|
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
private PictureInPictureSettings mFragment;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
FakeFeatureFactory.setupForTest(mContext);
|
||||||
|
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||||
|
mFragment = new PictureInPictureSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIgnoredApp() {
|
||||||
|
for (String ignoredPackage : mFragment.IGNORE_PACKAGE_LIST) {
|
||||||
|
assertThat(checkPackageHasPictureInPictureActivities(ignoredPackage, true))
|
||||||
|
.isFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNonPippableApp() {
|
||||||
|
assertThat(checkPackageHasPictureInPictureActivities("com.android.dummypackage")).isFalse();
|
||||||
|
assertThat(checkPackageHasPictureInPictureActivities("com.android.dummypackage",
|
||||||
|
false, false, false)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPippableApp() {
|
||||||
|
assertThat(checkPackageHasPictureInPictureActivities("com.android.dummypackage",
|
||||||
|
true)).isTrue();
|
||||||
|
assertThat(checkPackageHasPictureInPictureActivities("com.android.dummypackage",
|
||||||
|
false, true)).isTrue();
|
||||||
|
assertThat(checkPackageHasPictureInPictureActivities("com.android.dummypackage",
|
||||||
|
true, false)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void logSpecialPermissionChange() {
|
||||||
|
mFragment.logSpecialPermissionChange(true, "app");
|
||||||
|
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||||
|
eq(MetricsProto.MetricsEvent.APP_PICTURE_IN_PICTURE_ON_HIDE_ALLOW), eq("app"));
|
||||||
|
|
||||||
|
mFragment.logSpecialPermissionChange(false, "app");
|
||||||
|
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||||
|
eq(MetricsProto.MetricsEvent.APP_PICTURE_IN_PICTURE_ON_HIDE_DENY), eq("app"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkPackageHasPictureInPictureActivities(String packageName,
|
||||||
|
boolean... resizeableActivityState) {
|
||||||
|
ActivityInfoWrapper[] activities = null;
|
||||||
|
if (resizeableActivityState.length > 0) {
|
||||||
|
activities = new ActivityInfoWrapper[resizeableActivityState.length];
|
||||||
|
for (int i = 0; i < activities.length; i++) {
|
||||||
|
activities[i] = new MockActivityInfo(resizeableActivityState[i]
|
||||||
|
? ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE
|
||||||
|
: ActivityInfo.RESIZE_MODE_UNRESIZEABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PictureInPictureSettings.checkPackageHasPictureInPictureActivities(packageName,
|
||||||
|
activities);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MockActivityInfo implements ActivityInfoWrapper {
|
||||||
|
|
||||||
|
private int mResizeMode;
|
||||||
|
|
||||||
|
public MockActivityInfo(int resizeMode) {
|
||||||
|
mResizeMode = resizeMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getResizeMode() {
|
||||||
|
return mResizeMode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user