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 17 package com.android.internal.app; 18 19 import android.app.AppOpsManager; 20 import android.app.AsyncNotedAppOp; 21 import android.app.SyncNotedAppOp; 22 import android.app.RuntimeAppOpAccessMessage; 23 import android.content.AttributionSource; 24 import android.content.pm.ParceledListSlice; 25 import android.os.Bundle; 26 import android.os.PackageTagsList; 27 import android.os.RemoteCallback; 28 import com.android.internal.app.IAppOpsCallback; 29 import com.android.internal.app.IAppOpsActiveCallback; 30 import com.android.internal.app.IAppOpsAsyncNotedCallback; 31 import com.android.internal.app.IAppOpsNotedCallback; 32 import com.android.internal.app.IAppOpsStartedCallback; 33 import com.android.internal.app.MessageSamplingConfig; 34 35 interface IAppOpsService { 36 // These methods are also called by native code, so must 37 // be kept in sync with frameworks/native/libs/permission/include/binder/IAppOpsService.h 38 // and not be reordered checkOperation(int code, int uid, String packageName)39 int checkOperation(int code, int uid, String packageName); noteOperation(int code, int uid, String packageName, @nullable String attributionTag, boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage)40 SyncNotedAppOp noteOperation(int code, int uid, String packageName, @nullable String attributionTag, 41 boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage); startOperation(IBinder clientId, int code, int uid, String packageName, @nullable String attributionTag, boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage, int attributionFlags, int attributionChainId)42 SyncNotedAppOp startOperation(IBinder clientId, int code, int uid, String packageName, 43 @nullable String attributionTag, boolean startIfModeDefault, 44 boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage, 45 int attributionFlags, int attributionChainId); 46 @UnsupportedAppUsage finishOperation(IBinder clientId, int code, int uid, String packageName, @nullable String attributionTag)47 void finishOperation(IBinder clientId, int code, int uid, String packageName, 48 @nullable String attributionTag); startWatchingMode(int op, String packageName, IAppOpsCallback callback)49 void startWatchingMode(int op, String packageName, IAppOpsCallback callback); stopWatchingMode(IAppOpsCallback callback)50 void stopWatchingMode(IAppOpsCallback callback); permissionToOpCode(String permission)51 int permissionToOpCode(String permission); checkAudioOperation(int code, int usage, int uid, String packageName)52 int checkAudioOperation(int code, int usage, int uid, String packageName); shouldCollectNotes(int opCode)53 boolean shouldCollectNotes(int opCode); setCameraAudioRestriction(int mode)54 void setCameraAudioRestriction(int mode); startWatchingModeWithFlags(int op, String packageName, int flags, IAppOpsCallback callback)55 void startWatchingModeWithFlags(int op, String packageName, int flags, 56 IAppOpsCallback callback); 57 // End of methods also called by native code. 58 // Any new method exposed to native must be added after the last one, do not reorder 59 noteProxyOperation(int code, in AttributionSource attributionSource, boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage, boolean skipProxyOperation)60 SyncNotedAppOp noteProxyOperation(int code, in AttributionSource attributionSource, 61 boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage, 62 boolean skipProxyOperation); startProxyOperation(IBinder clientId, int code, in AttributionSource attributionSource, boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage, boolean skipProxyOperation, int proxyAttributionFlags, int proxiedAttributionFlags, int attributionChainId)63 SyncNotedAppOp startProxyOperation(IBinder clientId, int code, 64 in AttributionSource attributionSource, boolean startIfModeDefault, 65 boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage, 66 boolean skipProxyOperation, int proxyAttributionFlags, int proxiedAttributionFlags, 67 int attributionChainId); finishProxyOperation(IBinder clientId, int code, in AttributionSource attributionSource, boolean skipProxyOperation)68 void finishProxyOperation(IBinder clientId, int code, in AttributionSource attributionSource, 69 boolean skipProxyOperation); 70 71 // Remaining methods are only used in Java. checkPackage(int uid, String packageName)72 int checkPackage(int uid, String packageName); collectRuntimeAppOpAccessMessage()73 RuntimeAppOpAccessMessage collectRuntimeAppOpAccessMessage(); reportRuntimeAppOpAccessMessageAndGetConfig(String packageName, in SyncNotedAppOp appOp, String message)74 MessageSamplingConfig reportRuntimeAppOpAccessMessageAndGetConfig(String packageName, 75 in SyncNotedAppOp appOp, String message); 76 @UnsupportedAppUsage getPackagesForOps(in int[] ops)77 List<AppOpsManager.PackageOps> getPackagesForOps(in int[] ops); 78 @UnsupportedAppUsage getOpsForPackage(int uid, String packageName, in int[] ops)79 List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName, in int[] ops); getHistoricalOps(int uid, String packageName, String attributionTag, in List<String> ops, int historyFlags, int filter, long beginTimeMillis, long endTimeMillis, int flags, in RemoteCallback callback)80 void getHistoricalOps(int uid, String packageName, String attributionTag, in List<String> ops, 81 int historyFlags, int filter, long beginTimeMillis, long endTimeMillis, int flags, 82 in RemoteCallback callback); getHistoricalOpsFromDiskRaw(int uid, String packageName, String attributionTag, in List<String> ops, int historyFlags, int filter, long beginTimeMillis, long endTimeMillis, int flags, in RemoteCallback callback)83 void getHistoricalOpsFromDiskRaw(int uid, String packageName, String attributionTag, 84 in List<String> ops, int historyFlags, int filter, long beginTimeMillis, 85 long endTimeMillis, int flags, in RemoteCallback callback); offsetHistory(long duration)86 void offsetHistory(long duration); setHistoryParameters(int mode, long baseSnapshotInterval, int compressionStep)87 void setHistoryParameters(int mode, long baseSnapshotInterval, int compressionStep); addHistoricalOps(in AppOpsManager.HistoricalOps ops)88 void addHistoricalOps(in AppOpsManager.HistoricalOps ops); resetHistoryParameters()89 void resetHistoryParameters(); resetPackageOpsNoHistory(String packageName)90 void resetPackageOpsNoHistory(String packageName); clearHistory()91 void clearHistory(); rebootHistory(long offlineDurationMillis)92 void rebootHistory(long offlineDurationMillis); getUidOps(int uid, in int[] ops)93 List<AppOpsManager.PackageOps> getUidOps(int uid, in int[] ops); setUidMode(int code, int uid, int mode)94 void setUidMode(int code, int uid, int mode); 95 @UnsupportedAppUsage setMode(int code, int uid, String packageName, int mode)96 void setMode(int code, int uid, String packageName, int mode); 97 @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553) resetAllModes(int reqUserId, String reqPackageName)98 void resetAllModes(int reqUserId, String reqPackageName); setAudioRestriction(int code, int usage, int uid, int mode, in String[] exceptionPackages)99 void setAudioRestriction(int code, int usage, int uid, int mode, in String[] exceptionPackages); 100 setUserRestrictions(in Bundle restrictions, IBinder token, int userHandle)101 void setUserRestrictions(in Bundle restrictions, IBinder token, int userHandle); setUserRestriction(int code, boolean restricted, IBinder token, int userHandle, in PackageTagsList excludedPackageTags)102 void setUserRestriction(int code, boolean restricted, IBinder token, int userHandle, in PackageTagsList excludedPackageTags); 103 removeUser(int userHandle)104 void removeUser(int userHandle); 105 startWatchingActive(in int[] ops, IAppOpsActiveCallback callback)106 void startWatchingActive(in int[] ops, IAppOpsActiveCallback callback); stopWatchingActive(IAppOpsActiveCallback callback)107 void stopWatchingActive(IAppOpsActiveCallback callback); isOperationActive(int code, int uid, String packageName)108 boolean isOperationActive(int code, int uid, String packageName); isProxying(int op, String proxyPackageName, String proxyAttributionTag, int proxiedUid, String proxiedPackageName)109 boolean isProxying(int op, String proxyPackageName, String proxyAttributionTag, int proxiedUid, 110 String proxiedPackageName); 111 startWatchingStarted(in int[] ops, IAppOpsStartedCallback callback)112 void startWatchingStarted(in int[] ops, IAppOpsStartedCallback callback); stopWatchingStarted(IAppOpsStartedCallback callback)113 void stopWatchingStarted(IAppOpsStartedCallback callback); 114 startWatchingNoted(in int[] ops, IAppOpsNotedCallback callback)115 void startWatchingNoted(in int[] ops, IAppOpsNotedCallback callback); stopWatchingNoted(IAppOpsNotedCallback callback)116 void stopWatchingNoted(IAppOpsNotedCallback callback); 117 startWatchingAsyncNoted(String packageName, IAppOpsAsyncNotedCallback callback)118 void startWatchingAsyncNoted(String packageName, IAppOpsAsyncNotedCallback callback); stopWatchingAsyncNoted(String packageName, IAppOpsAsyncNotedCallback callback)119 void stopWatchingAsyncNoted(String packageName, IAppOpsAsyncNotedCallback callback); extractAsyncOps(String packageName)120 List<AsyncNotedAppOp> extractAsyncOps(String packageName); 121 checkOperationRaw(int code, int uid, String packageName, @nullable String attributionTag)122 int checkOperationRaw(int code, int uid, String packageName, @nullable String attributionTag); 123 reloadNonHistoricalState()124 void reloadNonHistoricalState(); 125 collectNoteOpCallsForValidation(String stackTrace, int op, String packageName, long version)126 void collectNoteOpCallsForValidation(String stackTrace, int op, String packageName, long version); 127 } 128