Correct picture-in-picture setting behavior for managed profile.
- Show picture-in-picture setting in the app info page for managed profile. - Navigate to work app setting instead of non-work app setting on tapping setting icon from picture-in-picture window. This requires correctly processing passed-in UserHandle to fetch the right package info. Bug: 71592457 Test: make RunSettingsRoboTests Change-Id: Id3dd04e88a57ae3d8c319c17615992637128589b
This commit is contained in:
@@ -128,23 +128,27 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
|
|||||||
protected String retrieveAppEntry() {
|
protected String retrieveAppEntry() {
|
||||||
final Bundle args = getArguments();
|
final Bundle args = getArguments();
|
||||||
mPackageName = (args != null) ? args.getString(ARG_PACKAGE_NAME) : null;
|
mPackageName = (args != null) ? args.getString(ARG_PACKAGE_NAME) : null;
|
||||||
|
Intent intent = (args == null) ?
|
||||||
|
getIntent() : (Intent) args.getParcelable("intent");
|
||||||
if (mPackageName == null) {
|
if (mPackageName == null) {
|
||||||
Intent intent = (args == null) ?
|
|
||||||
getActivity().getIntent() : (Intent) args.getParcelable("intent");
|
|
||||||
if (intent != null && intent.getData() != null) {
|
if (intent != null && intent.getData() != null) {
|
||||||
mPackageName = intent.getData().getSchemeSpecificPart();
|
mPackageName = intent.getData().getSchemeSpecificPart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mUserId = UserHandle.myUserId();
|
if (intent != null && intent.hasExtra(Intent.EXTRA_USER_HANDLE)) {
|
||||||
|
mUserId = ((UserHandle) intent.getParcelableExtra(
|
||||||
|
Intent.EXTRA_USER_HANDLE)).getIdentifier();
|
||||||
|
} else {
|
||||||
|
mUserId = UserHandle.myUserId();
|
||||||
|
}
|
||||||
mAppEntry = mState.getEntry(mPackageName, mUserId);
|
mAppEntry = mState.getEntry(mPackageName, mUserId);
|
||||||
if (mAppEntry != null) {
|
if (mAppEntry != null) {
|
||||||
// Get application info again to refresh changed properties of application
|
// Get application info again to refresh changed properties of application
|
||||||
try {
|
try {
|
||||||
mPackageInfo = mPm.getPackageInfo(mAppEntry.info.packageName,
|
mPackageInfo = mPm.getPackageInfoAsUser(mAppEntry.info.packageName,
|
||||||
PackageManager.MATCH_DISABLED_COMPONENTS |
|
PackageManager.MATCH_DISABLED_COMPONENTS |
|
||||||
PackageManager.MATCH_ANY_USER |
|
PackageManager.GET_SIGNING_CERTIFICATES |
|
||||||
PackageManager.GET_SIGNATURES |
|
PackageManager.GET_PERMISSIONS, mUserId);
|
||||||
PackageManager.GET_PERMISSIONS);
|
|
||||||
} catch (NameNotFoundException e) {
|
} catch (NameNotFoundException e) {
|
||||||
Log.e(TAG, "Exception when retrieving package:" + mAppEntry.info.packageName, e);
|
Log.e(TAG, "Exception when retrieving package:" + mAppEntry.info.packageName, e);
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,6 @@ import android.content.Context;
|
|||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -44,9 +43,6 @@ public class PictureInPictureDetailPreferenceController extends AppInfoPreferenc
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
if (UserManager.get(mContext).isManagedProfile()) {
|
|
||||||
return DISABLED_FOR_USER;
|
|
||||||
}
|
|
||||||
return hasPictureInPictureActivites() ? AVAILABLE : DISABLED_FOR_USER;
|
return hasPictureInPictureActivites() ? AVAILABLE : DISABLED_FOR_USER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,6 +30,8 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.support.v7.preference.PreferenceManager;
|
import android.support.v7.preference.PreferenceManager;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
@@ -116,12 +118,66 @@ public class AppInfoWithHeaderTest {
|
|||||||
assertThat(mAppInfoWithHeader.mPackageRemovedCalled).isTrue();
|
assertThat(mAppInfoWithHeader.mPackageRemovedCalled).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void noExtraUserHandleInIntent_retrieveAppEntryWithMyUsedId()
|
||||||
|
throws PackageManager.NameNotFoundException {
|
||||||
|
final String packageName = "com.android.settings";
|
||||||
|
|
||||||
|
mAppInfoWithHeader.mIntent.setData(Uri.fromParts("package",
|
||||||
|
packageName, null));
|
||||||
|
final ApplicationsState.AppEntry entry = mock(ApplicationsState.AppEntry.class);
|
||||||
|
entry.info = new ApplicationInfo();
|
||||||
|
entry.info.packageName = packageName;
|
||||||
|
|
||||||
|
when(mAppInfoWithHeader.mState.getEntry(packageName,
|
||||||
|
UserHandle.myUserId())).thenReturn(entry);
|
||||||
|
when(mAppInfoWithHeader.mPm.getPackageInfoAsUser(entry.info.packageName,
|
||||||
|
PackageManager.MATCH_DISABLED_COMPONENTS |
|
||||||
|
PackageManager.GET_SIGNING_CERTIFICATES |
|
||||||
|
PackageManager.GET_PERMISSIONS, UserHandle.myUserId())).thenReturn(
|
||||||
|
mAppInfoWithHeader.mPackageInfo);
|
||||||
|
|
||||||
|
mAppInfoWithHeader.retrieveAppEntry();
|
||||||
|
|
||||||
|
assertThat(mAppInfoWithHeader.mUserId).isEqualTo(UserHandle.myUserId());
|
||||||
|
assertThat(mAppInfoWithHeader.mPackageInfo).isNotNull();
|
||||||
|
assertThat(mAppInfoWithHeader.mAppEntry).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void extraUserHandleInIntent_retrieveAppEntryWithMyUsedId()
|
||||||
|
throws PackageManager.NameNotFoundException {
|
||||||
|
final int USER_ID = 1002;
|
||||||
|
final String packageName = "com.android.settings";
|
||||||
|
|
||||||
|
mAppInfoWithHeader.mIntent.putExtra(Intent.EXTRA_USER_HANDLE, new UserHandle(USER_ID));
|
||||||
|
mAppInfoWithHeader.mIntent.setData(Uri.fromParts("package",
|
||||||
|
packageName, null));
|
||||||
|
final ApplicationsState.AppEntry entry = mock(ApplicationsState.AppEntry.class);
|
||||||
|
entry.info = new ApplicationInfo();
|
||||||
|
entry.info.packageName = packageName;
|
||||||
|
|
||||||
|
when(mAppInfoWithHeader.mState.getEntry(packageName, USER_ID)).thenReturn(entry);
|
||||||
|
when(mAppInfoWithHeader.mPm.getPackageInfoAsUser(entry.info.packageName,
|
||||||
|
PackageManager.MATCH_DISABLED_COMPONENTS |
|
||||||
|
PackageManager.GET_SIGNING_CERTIFICATES |
|
||||||
|
PackageManager.GET_PERMISSIONS, USER_ID)).thenReturn(
|
||||||
|
mAppInfoWithHeader.mPackageInfo);
|
||||||
|
|
||||||
|
mAppInfoWithHeader.retrieveAppEntry();
|
||||||
|
|
||||||
|
assertThat(mAppInfoWithHeader.mUserId).isEqualTo(USER_ID);
|
||||||
|
assertThat(mAppInfoWithHeader.mPackageInfo).isNotNull();
|
||||||
|
assertThat(mAppInfoWithHeader.mAppEntry).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
public static class TestFragment extends AppInfoWithHeader {
|
public static class TestFragment extends AppInfoWithHeader {
|
||||||
|
|
||||||
PreferenceManager mManager;
|
PreferenceManager mManager;
|
||||||
PreferenceScreen mScreen;
|
PreferenceScreen mScreen;
|
||||||
Context mShadowContext;
|
Context mShadowContext;
|
||||||
boolean mPackageRemovedCalled;
|
boolean mPackageRemovedCalled;
|
||||||
|
Intent mIntent;
|
||||||
|
|
||||||
public TestFragment() {
|
public TestFragment() {
|
||||||
mPm = mock(PackageManager.class);
|
mPm = mock(PackageManager.class);
|
||||||
@@ -129,6 +185,8 @@ public class AppInfoWithHeaderTest {
|
|||||||
mScreen = mock(PreferenceScreen.class);
|
mScreen = mock(PreferenceScreen.class);
|
||||||
mPackageInfo = new PackageInfo();
|
mPackageInfo = new PackageInfo();
|
||||||
mPackageInfo.applicationInfo = new ApplicationInfo();
|
mPackageInfo.applicationInfo = new ApplicationInfo();
|
||||||
|
mState = mock(ApplicationsState.class);
|
||||||
|
mIntent = new Intent();
|
||||||
mShadowContext = ShadowApplication.getInstance().getApplicationContext();
|
mShadowContext = ShadowApplication.getInstance().getApplicationContext();
|
||||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||||
(InstantAppDataProvider) (info -> false));
|
(InstantAppDataProvider) (info -> false));
|
||||||
@@ -169,6 +227,8 @@ public class AppInfoWithHeaderTest {
|
|||||||
protected void onPackageRemoved() {
|
protected void onPackageRemoved() {
|
||||||
mPackageRemovedCalled = true;
|
mPackageRemovedCalled = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Intent getIntent() { return mIntent; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,6 @@ import static org.mockito.Mockito.verify;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserManager;
|
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -43,8 +42,6 @@ import org.robolectric.annotation.Config;
|
|||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class PictureInPictureDetailPreferenceControllerTest {
|
public class PictureInPictureDetailPreferenceControllerTest {
|
||||||
|
|
||||||
@Mock
|
|
||||||
private UserManager mUserManager;
|
|
||||||
@Mock
|
@Mock
|
||||||
private AppInfoDashboardFragment mFragment;
|
private AppInfoDashboardFragment mFragment;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -57,7 +54,6 @@ public class PictureInPictureDetailPreferenceControllerTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
|
||||||
|
|
||||||
mController = spy(
|
mController = spy(
|
||||||
new PictureInPictureDetailPreferenceController(mContext, mFragment, "Package1"));
|
new PictureInPictureDetailPreferenceController(mContext, mFragment, "Package1"));
|
||||||
@@ -65,16 +61,8 @@ public class PictureInPictureDetailPreferenceControllerTest {
|
|||||||
when(mPreference.getKey()).thenReturn(key);
|
when(mPreference.getKey()).thenReturn(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_managedProfile_shouldReturnDisabled() {
|
|
||||||
when(mUserManager.isManagedProfile()).thenReturn(true);
|
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.DISABLED_FOR_USER);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_noPictureInPictureActivities_shouldReturnDisabled() {
|
public void getAvailabilityStatus_noPictureInPictureActivities_shouldReturnDisabled() {
|
||||||
when(mUserManager.isManagedProfile()).thenReturn(false);
|
|
||||||
doReturn(false).when(mController).hasPictureInPictureActivites();
|
doReturn(false).when(mController).hasPictureInPictureActivites();
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.DISABLED_FOR_USER);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.DISABLED_FOR_USER);
|
||||||
@@ -82,7 +70,6 @@ public class PictureInPictureDetailPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_hasPictureInPictureActivities_shouldReturnAvailable() {
|
public void getAvailabilityStatus_hasPictureInPictureActivities_shouldReturnAvailable() {
|
||||||
when(mUserManager.isManagedProfile()).thenReturn(false);
|
|
||||||
doReturn(true).when(mController).hasPictureInPictureActivites();
|
doReturn(true).when(mController).hasPictureInPictureActivites();
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
|
||||||
|
Reference in New Issue
Block a user