Skip to content

Commit 83d1c72

Browse files
Evan SeversonCherrypicker Worker
authored andcommitted
Add AppOps overload to be able to watch foreground changes.
We have never offered the native API to register mode watchers that are invoked for foregroundness changes when the raw mode is MODE_FOREGROUND. Test: Add logging to verify invocation Bug: 247768581 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:949cb3d098fd98715826fc92ea3c26a51aa2d976) Merged-In: I89af46de557fbfc31d69613367a4e26a5222430a Change-Id: I89af46de557fbfc31d69613367a4e26a5222430a
1 parent 05f66b4 commit 83d1c72

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

libs/permission/AppOpsManager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ void AppOpsManager::startWatchingMode(int32_t op, const String16& packageName,
146146
}
147147
}
148148

149+
void AppOpsManager::startWatchingMode(int32_t op, const String16& packageName, int32_t flags,
150+
const sp<IAppOpsCallback>& callback) {
151+
sp<IAppOpsService> service = getService();
152+
if (service != nullptr) {
153+
service->startWatchingModeWithFlags(op, packageName, flags, callback);
154+
}
155+
}
156+
149157
void AppOpsManager::stopWatchingMode(const sp<IAppOpsCallback>& callback) {
150158
sp<IAppOpsService> service = getService();
151159
if (service != nullptr) {

libs/permission/IAppOpsService.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ class BpAppOpsService : public BpInterface<IAppOpsService>
166166
}
167167
return reply.readBool();
168168
}
169+
170+
virtual void startWatchingModeWithFlags(int32_t op, const String16& packageName,
171+
int32_t flags, const sp<IAppOpsCallback>& callback) {
172+
Parcel data, reply;
173+
data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
174+
data.writeInt32(op);
175+
data.writeString16(packageName);
176+
data.writeInt32(flags);
177+
data.writeStrongBinder(IInterface::asBinder(callback));
178+
remote()->transact(START_WATCHING_MODE_WITH_FLAGS_TRANSACTION, data, &reply);
179+
}
169180
};
170181

171182
IMPLEMENT_META_INTERFACE(AppOpsService, "com.android.internal.app.IAppOpsService")

libs/permission/include/binder/AppOpsManager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ class AppOpsManager
151151
_NUM_OP = 117
152152
};
153153

154+
enum {
155+
WATCH_FOREGROUND_CHANGES = 1 << 0
156+
};
157+
154158
AppOpsManager();
155159

156160
int32_t checkOp(int32_t op, int32_t uid, const String16& callingPackage);
@@ -174,6 +178,8 @@ class AppOpsManager
174178
const std::optional<String16>& attributionTag);
175179
void startWatchingMode(int32_t op, const String16& packageName,
176180
const sp<IAppOpsCallback>& callback);
181+
void startWatchingMode(int32_t op, const String16& packageName, int32_t flags,
182+
const sp<IAppOpsCallback>& callback);
177183
void stopWatchingMode(const sp<IAppOpsCallback>& callback);
178184
int32_t permissionToOpCode(const String16& permission);
179185
void setCameraAudioRestriction(int32_t mode);

libs/permission/include/binder/IAppOpsService.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class IAppOpsService : public IInterface
5252
const String16& packageName) = 0;
5353
virtual void setCameraAudioRestriction(int32_t mode) = 0;
5454
virtual bool shouldCollectNotes(int32_t opCode) = 0;
55+
virtual void startWatchingModeWithFlags(int32_t op, const String16& packageName,
56+
int32_t flags, const sp<IAppOpsCallback>& callback) = 0;
5557

5658
enum {
5759
CHECK_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
@@ -64,6 +66,7 @@ class IAppOpsService : public IInterface
6466
CHECK_AUDIO_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+7,
6567
SHOULD_COLLECT_NOTES_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+8,
6668
SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+9,
69+
START_WATCHING_MODE_WITH_FLAGS_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+10,
6770
};
6871

6972
enum {

0 commit comments

Comments
 (0)