Merge "Add APEX UIDs to PackageManager query" into rvc-dev am: cb29fa9384

Change-Id: I921986b08fe9d61c438c2d6ade620f986742bac4
This commit is contained in:
Jeffrey Huang
2020-04-09 23:34:59 +00:00
committed by Automerger Merge Worker
2 changed files with 22 additions and 41 deletions

View File

@@ -59,9 +59,6 @@ interface IStatsCompanionService {
/** Cancel any alarm for the purpose of subscriber triggering. */
oneway void cancelAlarmForSubscriberTriggering();
/** Tells StatsCompaionService to grab the uid map snapshot and send it to statsd. */
oneway void triggerUidSnapshot();
/**
* Ask StatsCompanionService if the given permission is allowed for a particular process
* and user ID. statsd is incapable of doing this check itself because checkCallingPermission

View File

@@ -153,7 +153,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
}
}
private static void informAllUidsLocked(Context context) throws RemoteException {
private static void informAllUids(Context context) {
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
PackageManager pm = context.getPackageManager();
final List<UserHandle> users = um.getUserHandles(true);
@@ -168,18 +168,26 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
Log.e(TAG, "Failed to create a pipe to send uid map data.", e);
return;
}
sStatsd.informAllUidData(fds[0]);
try {
fds[0].close();
} catch (IOException e) {
Log.e(TAG, "Failed to close the read side of the pipe.", e);
}
final ParcelFileDescriptor writeFd = fds[1];
HandlerThread backgroundThread = new HandlerThread(
"statsCompanionService.bg", THREAD_PRIORITY_BACKGROUND);
backgroundThread.start();
Handler handler = new Handler(backgroundThread.getLooper());
handler.post(() -> {
IStatsd statsd = getStatsdNonblocking();
if (statsd == null) {
return;
}
try {
statsd.informAllUidData(fds[0]);
} catch (RemoteException e) {
Log.e(TAG, "Failed to send uid map to statsd");
}
try {
fds[0].close();
} catch (IOException e) {
Log.e(TAG, "Failed to close the read side of the pipe.", e);
}
final ParcelFileDescriptor writeFd = fds[1];
FileOutputStream fout = new ParcelFileDescriptor.AutoCloseOutputStream(writeFd);
try {
ProtoOutputStream output = new ProtoOutputStream(fout);
@@ -188,7 +196,8 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
for (UserHandle userHandle : users) {
List<PackageInfo> pi =
pm.getInstalledPackagesAsUser(PackageManager.MATCH_UNINSTALLED_PACKAGES
| PackageManager.MATCH_ANY_USER,
| PackageManager.MATCH_ANY_USER
| PackageManager.MATCH_APEX,
userHandle.getIdentifier());
for (int j = 0; j < pi.size(); j++) {
if (pi.get(j).applicationInfo != null) {
@@ -319,19 +328,9 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
private static final class UserUpdateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
synchronized (sStatsdLock) {
if (sStatsd == null) {
Log.w(TAG, "Could not access statsd for UserUpdateReceiver");
return;
}
try {
// Pull the latest state of UID->app name, version mapping.
// Needed since the new user basically has a version of every app.
informAllUidsLocked(context);
} catch (RemoteException e) {
Log.e(TAG, "Failed to inform statsd latest update of all apps", e);
}
}
// Pull the latest state of UID->app name, version mapping.
// Needed since the new user basically has a version of every app.
informAllUids(context);
}
}
@@ -588,21 +587,6 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
}
}
@Override // Binder call
public void triggerUidSnapshot() {
StatsCompanion.enforceStatsdCallingUid();
synchronized (sStatsdLock) {
final long token = Binder.clearCallingIdentity();
try {
informAllUidsLocked(mContext);
} catch (RemoteException e) {
Log.e(TAG, "Failed to trigger uid snapshot.", e);
} finally {
Binder.restoreCallingIdentity(token);
}
}
}
@Override // Binder call
public boolean checkPermission(String permission, int pid, int uid) {
StatsCompanion.enforceStatsdCallingUid();
@@ -707,7 +691,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
try {
// Pull the latest state of UID->app name, version mapping when
// statsd starts.
informAllUidsLocked(mContext);
informAllUids(mContext);
} finally {
Binder.restoreCallingIdentity(token);
}