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() {
|
||||
final Bundle args = getArguments();
|
||||
mPackageName = (args != null) ? args.getString(ARG_PACKAGE_NAME) : null;
|
||||
Intent intent = (args == null) ?
|
||||
getIntent() : (Intent) args.getParcelable("intent");
|
||||
if (mPackageName == null) {
|
||||
Intent intent = (args == null) ?
|
||||
getActivity().getIntent() : (Intent) args.getParcelable("intent");
|
||||
if (intent != null && intent.getData() != null) {
|
||||
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);
|
||||
if (mAppEntry != null) {
|
||||
// Get application info again to refresh changed properties of application
|
||||
try {
|
||||
mPackageInfo = mPm.getPackageInfo(mAppEntry.info.packageName,
|
||||
mPackageInfo = mPm.getPackageInfoAsUser(mAppEntry.info.packageName,
|
||||
PackageManager.MATCH_DISABLED_COMPONENTS |
|
||||
PackageManager.MATCH_ANY_USER |
|
||||
PackageManager.GET_SIGNATURES |
|
||||
PackageManager.GET_PERMISSIONS);
|
||||
PackageManager.GET_SIGNING_CERTIFICATES |
|
||||
PackageManager.GET_PERMISSIONS, mUserId);
|
||||
} catch (NameNotFoundException 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.PackageManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.util.Log;
|
||||
@@ -44,9 +43,6 @@ public class PictureInPictureDetailPreferenceController extends AppInfoPreferenc
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (UserManager.get(mContext).isManagedProfile()) {
|
||||
return 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.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
@@ -116,12 +118,66 @@ public class AppInfoWithHeaderTest {
|
||||
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 {
|
||||
|
||||
PreferenceManager mManager;
|
||||
PreferenceScreen mScreen;
|
||||
Context mShadowContext;
|
||||
boolean mPackageRemovedCalled;
|
||||
Intent mIntent;
|
||||
|
||||
public TestFragment() {
|
||||
mPm = mock(PackageManager.class);
|
||||
@@ -129,6 +185,8 @@ public class AppInfoWithHeaderTest {
|
||||
mScreen = mock(PreferenceScreen.class);
|
||||
mPackageInfo = new PackageInfo();
|
||||
mPackageInfo.applicationInfo = new ApplicationInfo();
|
||||
mState = mock(ApplicationsState.class);
|
||||
mIntent = new Intent();
|
||||
mShadowContext = ShadowApplication.getInstance().getApplicationContext();
|
||||
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
|
||||
(InstantAppDataProvider) (info -> false));
|
||||
@@ -169,6 +227,8 @@ public class AppInfoWithHeaderTest {
|
||||
protected void onPackageRemoved() {
|
||||
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 android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -43,8 +42,6 @@ import org.robolectric.annotation.Config;
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class PictureInPictureDetailPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private AppInfoDashboardFragment mFragment;
|
||||
@Mock
|
||||
@@ -57,7 +54,6 @@ public class PictureInPictureDetailPreferenceControllerTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
|
||||
mController = spy(
|
||||
new PictureInPictureDetailPreferenceController(mContext, mFragment, "Package1"));
|
||||
@@ -65,16 +61,8 @@ public class PictureInPictureDetailPreferenceControllerTest {
|
||||
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
|
||||
public void getAvailabilityStatus_noPictureInPictureActivities_shouldReturnDisabled() {
|
||||
when(mUserManager.isManagedProfile()).thenReturn(false);
|
||||
doReturn(false).when(mController).hasPictureInPictureActivites();
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.DISABLED_FOR_USER);
|
||||
@@ -82,7 +70,6 @@ public class PictureInPictureDetailPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_hasPictureInPictureActivities_shouldReturnAvailable() {
|
||||
when(mUserManager.isManagedProfile()).thenReturn(false);
|
||||
doReturn(true).when(mController).hasPictureInPictureActivites();
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
|
||||
|
Reference in New Issue
Block a user