Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
fixup! add config for Pixel Health app
Browse files Browse the repository at this point in the history
- don't block visibility to the Fitbit app, it has special integration with the Pixel Health app
- don't block visibility from current launcher to Pixel Health, but keep blocking it in the opposite
direction
  • Loading branch information
muhomorr authored and thestinger committed Sep 4, 2024
1 parent ef185a6 commit 6aa5c5d
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions services/core/java/com/android/server/pm/ext/PixelHealthHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

import android.Manifest;
import android.app.ActivityThread;
import android.app.role.RoleManager;
import android.content.ContentResolver;
import android.content.Context;
import android.ext.PackageId;

import com.android.internal.gmscompat.PlayStoreHooks;
import com.android.internal.pm.pkg.component.ParsedUsesPermission;
import com.android.internal.pm.pkg.parsing.PackageParsingHooks;
import com.android.role.RoleManagerLocal;
import com.android.server.LocalManagerRegistry;
import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.PackageStateInternal;

import java.util.Objects;
import java.util.Set;

class PixelHealthHooks extends PackageHooks {
static final String PERMISSION_FAR_INFRARED_TEMPERATURE =
"com.google.sensor.permission.FAR_INFRARED_TEMPERATURE";
Expand Down Expand Up @@ -53,19 +60,39 @@ public int overridePermissionState(String permission, int userId) {
}

@Override
public boolean shouldBlockPackageVisibility(int userId, PackageStateInternal otherPkg) {
if (otherPkg.isSystem()) {
public boolean shouldBlockPackageVisibility(int userId, PackageStateInternal otherPkg, boolean isSelfToOther) {
if (!isUserInstalledPkg(otherPkg)) {
return false;
}

if ("com.fitbit.FitbitMobile".equals(otherPkg.getPackageName())) {
// Pixel Health app performs Fitbit certificate checks itself
return false;
}

if (isSelfToOther) {
// hide all other user apps from Pixel Health app
return true;
}

AndroidPackage otherAPkg = otherPkg.getPkg();
if (otherAPkg != null && PackageExt.get(otherAPkg).getPackageId() == PackageId.PLAY_STORE) {
if (otherAPkg == null) {
return true;
}

if (PackageExt.get(otherAPkg).getPackageId() == PackageId.PLAY_STORE) {
Context ctx = ActivityThread.currentActivityThread().getSystemContext();
if (PlayStoreHooks.isInstallAllowed(PackageId.PIXEL_HEALTH_NAME, ctx.getContentResolver())) {
return false;
}
ContentResolver cr = ctx.getContentResolver();
return !PlayStoreHooks.isInstallAllowed(PackageId.PIXEL_HEALTH_NAME, cr);
}

return true;
RoleManagerLocal roleManager = Objects.requireNonNull(
LocalManagerRegistry.getManager(RoleManagerLocal.class)
);
Set<String> homeRoleHolders = roleManager.getRolesAndHolders(userId).get(RoleManager.ROLE_HOME);
// Don't block visiblity from current launcher to Pixel Health app. Association restrictions
// between them remain enforced.
boolean isAllowed = homeRoleHolders != null && homeRoleHolders.contains(otherAPkg.getPackageName());
return !isAllowed;
}
}

0 comments on commit 6aa5c5d

Please sign in to comment.