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); 55 // End of methods also called by native code. 56 // Any new method exposed to native must be added after the last one, do not reorder 57 noteProxyOperation(int code, in AttributionSource attributionSource, boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage, boolean skipProxyOperation)58 SyncNotedAppOp noteProxyOperation(int code, in AttributionSource attributionSource, 59 boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage, 60 boolean skipProxyOperation); startProxyOperation(int code, in AttributionSource attributionSource, boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage, boolean skipProxyOperation, int proxyAttributionFlags, int proxiedAttributionFlags, int attributionChainId)61 SyncNotedAppOp startProxyOperation(int code, in AttributionSource attributionSource, 62 boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, String message, 63 boolean shouldCollectMessage, boolean skipProxyOperation, int proxyAttributionFlags, 64 int proxiedAttributionFlags, int attributionChainId); finishProxyOperation(int code, in AttributionSource attributionSource, boolean skipProxyOperation)65 void finishProxyOperation(int code, in AttributionSource attributionSource, 66 boolean skipProxyOperation); 67 68 // Remaining methods are only used in Java. checkPackage(int uid, String packageName)69 int checkPackage(int uid, String packageName); collectRuntimeAppOpAccessMessage()70 RuntimeAppOpAccessMessage collectRuntimeAppOpAccessMessage(); reportRuntimeAppOpAccessMessageAndGetConfig(String packageName, in SyncNotedAppOp appOp, String message)71 MessageSamplingConfig reportRuntimeAppOpAccessMessageAndGetConfig(String packageName, 72 in SyncNotedAppOp appOp, String message); 73 @UnsupportedAppUsage getPackagesForOps(in int[] ops)74 List<AppOpsManager.PackageOps> getPackagesForOps(in int[] ops); 75 @UnsupportedAppUsage getOpsForPackage(int uid, String packageName, in int[] ops)76 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)77 void getHistoricalOps(int uid, String packageName, String attributionTag, in List<String> ops, 78 int historyFlags, int filter, long beginTimeMillis, long endTimeMillis, int flags, 79 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)80 void getHistoricalOpsFromDiskRaw(int uid, String packageName, String attributionTag, 81 in List<String> ops, int historyFlags, int filter, long beginTimeMillis, 82 long endTimeMillis, int flags, in RemoteCallback callback); offsetHistory(long duration)83 void offsetHistory(long duration); setHistoryParameters(int mode, long baseSnapshotInterval, int compressionStep)84 void setHistoryParameters(int mode, long baseSnapshotInterval, int compressionStep); addHistoricalOps(in AppOpsManager.HistoricalOps ops)85 void addHistoricalOps(in AppOpsManager.HistoricalOps ops); resetHistoryParameters()86 void resetHistoryParameters(); resetPackageOpsNoHistory(String packageName)87 void resetPackageOpsNoHistory(String packageName); clearHistory()88 void clearHistory(); rebootHistory(long offlineDurationMillis)89 void rebootHistory(long offlineDurationMillis); getUidOps(int uid, in int[] ops)90 List<AppOpsManager.PackageOps> getUidOps(int uid, in int[] ops); setUidMode(int code, int uid, int mode)91 void setUidMode(int code, int uid, int mode); 92 @UnsupportedAppUsage setMode(int code, int uid, String packageName, int mode)93 void setMode(int code, int uid, String packageName, int mode); 94 @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553) resetAllModes(int reqUserId, String reqPackageName)95 void resetAllModes(int reqUserId, String reqPackageName); setAudioRestriction(int code, int usage, int uid, int mode, in String[] exceptionPackages)96 void setAudioRestriction(int code, int usage, int uid, int mode, in String[] exceptionPackages); 97 setUserRestrictions(in Bundle restrictions, IBinder token, int userHandle)98 void setUserRestrictions(in Bundle restrictions, IBinder token, int userHandle); setUserRestriction(int code, boolean restricted, IBinder token, int userHandle, in PackageTagsList excludedPackageTags)99 void setUserRestriction(int code, boolean restricted, IBinder token, int userHandle, in PackageTagsList excludedPackageTags); 100 removeUser(int userHandle)101 void removeUser(int userHandle); 102 startWatchingActive(in int[] ops, IAppOpsActiveCallback callback)103 void startWatchingActive(in int[] ops, IAppOpsActiveCallback callback); stopWatchingActive(IAppOpsActiveCallback callback)104 void stopWatchingActive(IAppOpsActiveCallback callback); isOperationActive(int code, int uid, String packageName)105 boolean isOperationActive(int code, int uid, String packageName); isProxying(int op, String proxyPackageName, String proxyAttributionTag, int proxiedUid, String proxiedPackageName)106 boolean isProxying(int op, String proxyPackageName, String proxyAttributionTag, int proxiedUid, 107 String proxiedPackageName); 108 startWatchingStarted(in int[] ops, IAppOpsStartedCallback callback)109 void startWatchingStarted(in int[] ops, IAppOpsStartedCallback callback); stopWatchingStarted(IAppOpsStartedCallback callback)110 void stopWatchingStarted(IAppOpsStartedCallback callback); 111 startWatchingModeWithFlags(int op, String packageName, int flags, IAppOpsCallback callback)112 void startWatchingModeWithFlags(int op, String packageName, int flags, IAppOpsCallback callback); 113 startWatchingNoted(in int[] ops, IAppOpsNotedCallback callback)114 void startWatchingNoted(in int[] ops, IAppOpsNotedCallback callback); stopWatchingNoted(IAppOpsNotedCallback callback)115 void stopWatchingNoted(IAppOpsNotedCallback callback); 116 startWatchingAsyncNoted(String packageName, IAppOpsAsyncNotedCallback callback)117 void startWatchingAsyncNoted(String packageName, IAppOpsAsyncNotedCallback callback); stopWatchingAsyncNoted(String packageName, IAppOpsAsyncNotedCallback callback)118 void stopWatchingAsyncNoted(String packageName, IAppOpsAsyncNotedCallback callback); extractAsyncOps(String packageName)119 List<AsyncNotedAppOp> extractAsyncOps(String packageName); 120 checkOperationRaw(int code, int uid, String packageName, @nullable String attributionTag)121 int checkOperationRaw(int code, int uid, String packageName, @nullable String attributionTag); 122 reloadNonHistoricalState()123 void reloadNonHistoricalState(); 124 collectNoteOpCallsForValidation(String stackTrace, int op, String packageName, long version)125 void collectNoteOpCallsForValidation(String stackTrace, int op, String packageName, long version); 126 } 127