Merge "Fix bugs found during cts test." into tm-dev

This commit is contained in:
Kathy Chen
2022-03-30 15:25:40 +00:00
committed by Android (Google) Code Review
2 changed files with 13 additions and 5 deletions

View File

@@ -217,9 +217,13 @@ final class AmbientContextManagerPerUserService extends
RemoteCallback detectionResultCallback, RemoteCallback statusCallback) { RemoteCallback detectionResultCallback, RemoteCallback statusCallback) {
Slog.d(TAG, "Requested detection of " + request.getEventTypes()); Slog.d(TAG, "Requested detection of " + request.getEventTypes());
synchronized (mLock) { synchronized (mLock) {
if (setUpServiceIfNeeded()) {
ensureRemoteServiceInitiated(); ensureRemoteServiceInitiated();
mRemoteService.startDetection(request, callingPackage, detectionResultCallback, mRemoteService.startDetection(request, callingPackage, detectionResultCallback,
statusCallback); statusCallback);
} else {
Slog.w(TAG, "No valid component found for AmbientContextDetectionService");
}
} }
} }
@@ -371,10 +375,12 @@ final class AmbientContextManagerPerUserService extends
void stopDetection(String packageName) { void stopDetection(String packageName) {
Slog.d(TAG, "Stop detection for " + packageName); Slog.d(TAG, "Stop detection for " + packageName);
synchronized (mLock) { synchronized (mLock) {
if (mComponentName != null) {
ensureRemoteServiceInitiated(); ensureRemoteServiceInitiated();
mRemoteService.stopDetection(packageName); mRemoteService.stopDetection(packageName);
} }
} }
}
@Nullable @Nullable
private PendingIntent findExistingRequestByPackage(String callingPackage) { private PendingIntent findExistingRequestByPackage(String callingPackage) {

View File

@@ -249,6 +249,8 @@ public class AmbientContextManagerService extends
Objects.requireNonNull(eventTypes); Objects.requireNonNull(eventTypes);
Objects.requireNonNull(callingPackage); Objects.requireNonNull(callingPackage);
assertCalledByPackageOwner(callingPackage); assertCalledByPackageOwner(callingPackage);
mContext.enforceCallingOrSelfPermission(
Manifest.permission.ACCESS_AMBIENT_CONTEXT_EVENT, TAG);
mService.onStartConsentActivity(eventTypes, callingPackage); mService.onStartConsentActivity(eventTypes, callingPackage);
} }