Merge "Add APEX UIDs to PackageManager query" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
cb29fa9384
@@ -59,9 +59,6 @@ interface IStatsCompanionService {
|
|||||||
/** Cancel any alarm for the purpose of subscriber triggering. */
|
/** Cancel any alarm for the purpose of subscriber triggering. */
|
||||||
oneway void cancelAlarmForSubscriberTriggering();
|
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
|
* 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
|
* and user ID. statsd is incapable of doing this check itself because checkCallingPermission
|
||||||
|
|||||||
@@ -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);
|
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
PackageManager pm = context.getPackageManager();
|
PackageManager pm = context.getPackageManager();
|
||||||
final List<UserHandle> users = um.getUserHandles(true);
|
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);
|
Log.e(TAG, "Failed to create a pipe to send uid map data.", e);
|
||||||
return;
|
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(
|
HandlerThread backgroundThread = new HandlerThread(
|
||||||
"statsCompanionService.bg", THREAD_PRIORITY_BACKGROUND);
|
"statsCompanionService.bg", THREAD_PRIORITY_BACKGROUND);
|
||||||
backgroundThread.start();
|
backgroundThread.start();
|
||||||
Handler handler = new Handler(backgroundThread.getLooper());
|
Handler handler = new Handler(backgroundThread.getLooper());
|
||||||
handler.post(() -> {
|
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);
|
FileOutputStream fout = new ParcelFileDescriptor.AutoCloseOutputStream(writeFd);
|
||||||
try {
|
try {
|
||||||
ProtoOutputStream output = new ProtoOutputStream(fout);
|
ProtoOutputStream output = new ProtoOutputStream(fout);
|
||||||
@@ -188,7 +196,8 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
|||||||
for (UserHandle userHandle : users) {
|
for (UserHandle userHandle : users) {
|
||||||
List<PackageInfo> pi =
|
List<PackageInfo> pi =
|
||||||
pm.getInstalledPackagesAsUser(PackageManager.MATCH_UNINSTALLED_PACKAGES
|
pm.getInstalledPackagesAsUser(PackageManager.MATCH_UNINSTALLED_PACKAGES
|
||||||
| PackageManager.MATCH_ANY_USER,
|
| PackageManager.MATCH_ANY_USER
|
||||||
|
| PackageManager.MATCH_APEX,
|
||||||
userHandle.getIdentifier());
|
userHandle.getIdentifier());
|
||||||
for (int j = 0; j < pi.size(); j++) {
|
for (int j = 0; j < pi.size(); j++) {
|
||||||
if (pi.get(j).applicationInfo != null) {
|
if (pi.get(j).applicationInfo != null) {
|
||||||
@@ -319,19 +328,9 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
|||||||
private static final class UserUpdateReceiver extends BroadcastReceiver {
|
private static final class UserUpdateReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
synchronized (sStatsdLock) {
|
// Pull the latest state of UID->app name, version mapping.
|
||||||
if (sStatsd == null) {
|
// Needed since the new user basically has a version of every app.
|
||||||
Log.w(TAG, "Could not access statsd for UserUpdateReceiver");
|
informAllUids(context);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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
|
@Override // Binder call
|
||||||
public boolean checkPermission(String permission, int pid, int uid) {
|
public boolean checkPermission(String permission, int pid, int uid) {
|
||||||
StatsCompanion.enforceStatsdCallingUid();
|
StatsCompanion.enforceStatsdCallingUid();
|
||||||
@@ -707,7 +691,7 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
|
|||||||
try {
|
try {
|
||||||
// Pull the latest state of UID->app name, version mapping when
|
// Pull the latest state of UID->app name, version mapping when
|
||||||
// statsd starts.
|
// statsd starts.
|
||||||
informAllUidsLocked(mContext);
|
informAllUids(mContext);
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(token);
|
Binder.restoreCallingIdentity(token);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user