IAppOpsCallback.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (C) 2013 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #define LOG_TAG "AppOpsCallback"
  17. #include <binder/IAppOpsCallback.h>
  18. #include <utils/Log.h>
  19. #include <binder/Parcel.h>
  20. #include <utils/String8.h>
  21. #include <private/binder/Static.h>
  22. namespace android {
  23. // ----------------------------------------------------------------------
  24. class BpAppOpsCallback : public BpInterface<IAppOpsCallback>
  25. {
  26. public:
  27. explicit BpAppOpsCallback(const sp<IBinder>& impl)
  28. : BpInterface<IAppOpsCallback>(impl)
  29. {
  30. }
  31. virtual void opChanged(int32_t op, const String16& packageName) {
  32. Parcel data, reply;
  33. data.writeInterfaceToken(IAppOpsCallback::getInterfaceDescriptor());
  34. data.writeInt32(op);
  35. data.writeString16(packageName);
  36. remote()->transact(OP_CHANGED_TRANSACTION, data, &reply);
  37. }
  38. };
  39. IMPLEMENT_META_INTERFACE(AppOpsCallback, "com.android.internal.app.IAppOpsCallback");
  40. // ----------------------------------------------------------------------
  41. // NOLINTNEXTLINE(google-default-arguments)
  42. status_t BnAppOpsCallback::onTransact(
  43. uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
  44. {
  45. switch(code) {
  46. case OP_CHANGED_TRANSACTION: {
  47. CHECK_INTERFACE(IAppOpsCallback, data, reply);
  48. int32_t op = data.readInt32();
  49. String16 packageName;
  50. (void)data.readString16(&packageName);
  51. opChanged(op, packageName);
  52. reply->writeNoException();
  53. return NO_ERROR;
  54. } break;
  55. default:
  56. return BBinder::onTransact(code, data, reply, flags);
  57. }
  58. }
  59. }; // namespace android