Skip to content

Commit 2fea2c6

Browse files
committed
InstallStart: trust play store in work profile
When a work profile with play services gets created Play Store can't install any apps as the work profile may have a policy active to forbid unknown sources as it is not aware that play store is not a system app and gets blocked by that policy. Here we detect if the play store is genuine and is trying to install an app in a work profile. If that is the case we allow it to proceed, despite not being a
1 parent 399a194 commit 2fea2c6

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/PackageInstaller/src/com/android/packageinstaller/InstallStart.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
import android.content.pm.PackageInstaller;
3232
import android.content.pm.PackageInstaller.SessionInfo;
3333
import android.content.pm.PackageManager;
34+
import android.content.pm.PackageManager.NameNotFoundException;
3435
import android.content.pm.ProviderInfo;
36+
import android.ext.PackageId;
3537
import android.net.Uri;
3638
import android.os.Build;
3739
import android.os.Bundle;
@@ -160,7 +162,22 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
160162
mAbortInstall = true;
161163
}
162164

163-
checkDevicePolicyRestrictions(isTrustedSource);
165+
// When a work profile with play services gets created Play Store can't install any apps
166+
// as the work profile may have a policy active to forbid unknown sources as it is not
167+
// aware that play store is not a system app and gets blocked by that policy.
168+
// Here we detect if the play store is genuine and is trying to install an app
169+
// in a work profile. If that is the case we allow it to proceed, despite not being a
170+
// trusted source.
171+
boolean isTrustedPlayStore = false;
172+
try {
173+
isTrustedPlayStore = callingPackage != null &&
174+
mPackageManager.getApplicationInfo(callingPackage, 0).ext().getPackageId() == PackageId.PLAY_STORE;
175+
} catch(NameNotFoundException e) {
176+
// Should never happen.
177+
}
178+
boolean isManagedProfile = mUserManager.isManagedProfile(mPackageManager.getUserId());
179+
180+
checkDevicePolicyRestrictions(isTrustedSource || (isTrustedPlayStore && isManagedProfile));
164181

165182
final String installerPackageNameFromIntent = getIntent().getStringExtra(
166183
Intent.EXTRA_INSTALLER_PACKAGE_NAME);

0 commit comments

Comments
 (0)