In the previous article "Learning HandlerThread" , we mentioned that although there is a getThreadHandler() method in the HandlerThread class to get the Handler, it is impossible for us to call it . Because this method is @hide
annotated with
/**
* @return a shared {@link Handler} associated with this thread
* @hide
*/
@NonNull
public Handler getThreadHandler() {
if (mHandler == null) {
mHandler = new Handler(getLooper());
}
return mHandler;
}
So let's take a look at @hide
what is sacred.
If the build.gradle of our android project is configured compileSdk 32
, then when we compile our android application, $ANDROID_SDK_HOME/platforms/android-32/android.jar
it will be added to our compile-time classpath and participate in the compilation of the app. @hide
It will control the things in the android.jar package we use when compiling.
android.jar is created as part of compiling android itself. Android framework classes are analyzed and copies of them are created. This copy has the following characteristics:
- Remove marked
@hide
classes, methods, fields, etc. - All remaining methods have stub implementations, namely
throw new RuntimeException("Stub!")
- Keep JavaDoc annotations of all classes, methods, and fields that have not been removed
Let's use the javap command to check the contents of android.os.HandlerThread.class:
% javap -verbose android/os/HandlerThread.class
From the following we can see that HandlerThread.class does not have a getThreadHandler method.
Classfile
***/adddd/android/android/os/HandlerThread.class
Last modified Jan 1, 2008; size 1043 bytes
SHA-256 checksum 8161f60748df5cf7489dbf189c3f4668d81a17595dbd55e52baa0f8263bb96d4
Compiled from "HandlerThread.java"
public class android.os.HandlerThread extends java.lang.Thread
minor version: 0
major version: 52
flags: (0x0021) ACC_PUBLIC, ACC_SUPER
this_class: #5 // android/os/HandlerThread
super_class: #6 // java/lang/Thread
interfaces: 0, fields: 0, methods: 8, attributes: 1
Constant pool:
#1 = Methodref #6.#31 // java/lang/Thread."<init>":()V
#2 = Class #32 // java/lang/RuntimeException
#3 = String #33 // Stub!
#4 = Methodref #2.#34 // java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
#5 = Class #35 // android/os/HandlerThread
#6 = Class #36 // java/lang/Thread
#7 = Utf8 <init>
#8 = Utf8 (Ljava/lang/String;)V
#9 = Utf8 Code
#10 = Utf8 LineNumberTable
#11 = Utf8 LocalVariableTable
#12 = Utf8 this
#13 = Utf8 Landroid/os/HandlerThread;
#14 = Utf8 name
#15 = Utf8 Ljava/lang/String;
#16 = Utf8 (Ljava/lang/String;I)V
#17 = Utf8 priority
#18 = Utf8 I
#19 = Utf8 onLooperPrepared
#20 = Utf8 ()V
#21 = Utf8 run
#22 = Utf8 getLooper
#23 = Utf8 ()Landroid/os/Looper;
#24 = Utf8 quit
#25 = Utf8 ()Z
#26 = Utf8 quitSafely
#27 = Utf8 getThreadId
#28 = Utf8 ()I
#29 = Utf8 SourceFile
#30 = Utf8 HandlerThread.java
#31 = NameAndType #7:#20 // "<init>":()V
#32 = Utf8 java/lang/RuntimeException
#33 = Utf8 Stub!
#34 = NameAndType #7:#8 // "<init>":(Ljava/lang/String;)V
#35 = Utf8 android/os/HandlerThread
#36 = Utf8 java/lang/Thread
{
public android.os.HandlerThread(java.lang.String);
descriptor: (Ljava/lang/String;)V
flags: (0x0001) ACC_PUBLIC
Code:
stack=3, locals=2, args_size=2
0: aload_0
1: invokespecial #1 // Method java/lang/Thread."<init>":()V
4: new #2 // class java/lang/RuntimeException
7: dup
8: ldc #3 // String Stub!
10: invokespecial #4 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
13: athrow
LineNumberTable:
line 23: 0
LocalVariableTable:
Start Length Slot Name Signature
0 14 0 this Landroid/os/HandlerThread;
0 14 1 name Ljava/lang/String;
public android.os.HandlerThread(java.lang.String, int);
descriptor: (Ljava/lang/String;I)V
flags: (0x0001) ACC_PUBLIC
Code:
stack=3, locals=3, args_size=3
0: aload_0
1: invokespecial #1 // Method java/lang/Thread."<init>":()V
4: new #2 // class java/lang/RuntimeException
7: dup
8: ldc #3 // String Stub!
10: invokespecial #4 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
13: athrow
LineNumberTable:
line 25: 0
LocalVariableTable:
Start Length Slot Name Signature
0 14 0 this Landroid/os/HandlerThread;
0 14 1 name Ljava/lang/String;
0 14 2 priority I
protected void onLooperPrepared();
descriptor: ()V
flags: (0x0004) ACC_PROTECTED
Code:
stack=3, locals=1, args_size=1
0: new #2 // class java/lang/RuntimeException
3: dup
4: ldc #3 // String Stub!
6: invokespecial #4 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
9: athrow
LineNumberTable:
line 27: 0
LocalVariableTable:
Start Length Slot Name Signature
0 10 0 this Landroid/os/HandlerThread;
public void run();
descriptor: ()V
flags: (0x0001) ACC_PUBLIC
Code:
stack=3, locals=1, args_size=1
0: new #2 // class java/lang/RuntimeException
3: dup
4: ldc #3 // String Stub!
6: invokespecial #4 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
9: athrow
LineNumberTable:
line 29: 0
LocalVariableTable:
Start Length Slot Name Signature
0 10 0 this Landroid/os/HandlerThread;
public android.os.Looper getLooper();
descriptor: ()Landroid/os/Looper;
flags: (0x0001) ACC_PUBLIC
Code:
stack=3, locals=1, args_size=1
0: new #2 // class java/lang/RuntimeException
3: dup
4: ldc #3 // String Stub!
6: invokespecial #4 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
9: athrow
LineNumberTable:
line 31: 0
LocalVariableTable:
Start Length Slot Name Signature
0 10 0 this Landroid/os/HandlerThread;
public boolean quit();
descriptor: ()Z
flags: (0x0001) ACC_PUBLIC
Code:
stack=3, locals=1, args_size=1
0: new #2 // class java/lang/RuntimeException
3: dup
4: ldc #3 // String Stub!
6: invokespecial #4 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
9: athrow
LineNumberTable:
line 33: 0
LocalVariableTable:
Start Length Slot Name Signature
0 10 0 this Landroid/os/HandlerThread;
public boolean quitSafely();
descriptor: ()Z
flags: (0x0001) ACC_PUBLIC
Code:
stack=3, locals=1, args_size=1
0: new #2 // class java/lang/RuntimeException
3: dup
4: ldc #3 // String Stub!
6: invokespecial #4 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
9: athrow
LineNumberTable:
line 35: 0
LocalVariableTable:
Start Length Slot Name Signature
0 10 0 this Landroid/os/HandlerThread;
public int getThreadId();
descriptor: ()I
flags: (0x0001) ACC_PUBLIC
Code:
stack=3, locals=1, args_size=1
0: new #2 // class java/lang/RuntimeException
3: dup
4: ldc #3 // String Stub!
6: invokespecial #4 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
9: athrow
LineNumberTable:
line 37: 0
LocalVariableTable:
Start Length Slot Name Signature
0 10 0 this Landroid/os/HandlerThread;
}
SourceFile: "HandlerThread.java"
Here is another introduction to some information seen from this HandlerThread.class:
- minor version: 0 major version: 52: Indicates which compiler is used to produce the current .class file
JDK Version | (in Decimal) Major Version |
---|---|
Java SE 8.0 | 52 |
Java SE 11.0 | 55 |
- Compiled from "HandlerThread.java": Indicates that the .class file is compiled from this "HandlerThread.java"