次の方法で共有


AppOpsManager.NoteOp Method

Definition

Overloads

NoteOp(String, Int32, String)

This member is deprecated.

NoteOp(String, Int32, String, String, String)

Make note of an application performing an operation and check if the application is allowed to perform it.

NoteOp(String, Int32, String)

This member is deprecated.

[Android.Runtime.Register("noteOp", "(Ljava/lang/String;ILjava/lang/String;)I", "GetNoteOp_Ljava_lang_String_ILjava_lang_String_Handler")]
public virtual Android.App.AppOpsManagerMode NoteOp (string op, int uid, string packageName);
[<Android.Runtime.Register("noteOp", "(Ljava/lang/String;ILjava/lang/String;)I", "GetNoteOp_Ljava_lang_String_ILjava_lang_String_Handler")>]
abstract member NoteOp : string * int * string -> Android.App.AppOpsManagerMode
override this.NoteOp : string * int * string -> Android.App.AppOpsManagerMode

Parameters

op
String

The operation to note. One of the OPSTR_* constants.

uid
Int32

The user id of the application attempting to perform the operation.

packageName
String

The name of the application attempting to perform the operation.

Returns

Attributes

Exceptions

If the app has been configured to crash on this op.

Remarks

This member is deprecated. Use #noteOp(String, int, String, String, String) instead

Java documentation for android.app.AppOpsManager.noteOp(java.lang.String, int, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

NoteOp(String, Int32, String, String, String)

Make note of an application performing an operation and check if the application is allowed to perform it.

[Android.Runtime.Register("noteOp", "(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", "GetNoteOp_Ljava_lang_String_ILjava_lang_String_Ljava_lang_String_Ljava_lang_String_Handler", ApiSince=30)]
public virtual Android.App.AppOpsManagerMode NoteOp (string op, int uid, string? packageName, string? attributionTag, string? message);
[<Android.Runtime.Register("noteOp", "(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", "GetNoteOp_Ljava_lang_String_ILjava_lang_String_Ljava_lang_String_Ljava_lang_String_Handler", ApiSince=30)>]
abstract member NoteOp : string * int * string * string * string -> Android.App.AppOpsManagerMode
override this.NoteOp : string * int * string * string * string -> Android.App.AppOpsManagerMode

Parameters

op
String

The operation to note. One of the OPSTR_* constants.

uid
Int32

The uid of the application attempting to perform the operation.

packageName
String

The name of the application attempting to perform the operation.

attributionTag
String

The Context#createAttributionContext attribution tag of the calling context or null for default attribution

message
String

A message describing why the op was noted

Returns

Returns #MODE_ALLOWED if the operation is allowed, or #MODE_IGNORED if it is not allowed and should be silently ignored (without causing the app to crash).

Attributes

Remarks

Make note of an application performing an operation and check if the application is allowed to perform it.

If this is a check that is not preceding the protected operation, use #unsafeCheckOp instead.

The identity of the package the app-op is noted for is specified by the uid and packageName parameters. If this is noted for a regular app both should be set and the package needs to be part of the uid. In the very rare case that an app-op is noted for an entity that does not have a package name, the package can be null. As it is possible that a single process contains more than one package the packageName should be Context#getPackageName() read from the context of the caller of the API (in the app process) that eventually triggers this check. If this op is not noted for a running process the packageName cannot be read from the context, but it should be clear which package the note is for.

If the uid and packageName do not match this return #MODE_IGNORED.

Beside the access check this method also records the access. While the access check is based on uid and/or packageName the access recording is done based on the packageName and attributionTag. The attributionTag should be Context#getAttributionTag() read from the same context the package name is read from. In the case the check is not related to an API call, the attributionTag should be null. Please note that e.g. registering a callback for later is still an API call and the code should store the attribution tag along the package name for being used in this method later.

The message parameter only needs to be set when this method is <ul>not</ul> called in a two-way binder call from the client. In this case the message is a free form text that is meant help the app developer determine what part of the app's code triggered the note. This message is passed back to the app in the OnOpNotedCallback#onAsyncNoted(AsyncNotedAppOp) callback. A good example of a useful message is including the System#identityHashCode(Object) of the listener that will receive data or the name of the manifest-receiver.

Java documentation for android.app.AppOpsManager.noteOp(java.lang.String, int, java.lang.String, java.lang.String, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to