Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2025-01-24 - [Developer-centric micro-UX in sample apps]
**Learning:** For technical sample apps, providing easy ways to copy terminal commands (like ADB) to the clipboard significantly improves developer experience. Persisting the state of library loading (native operations) across configuration changes ensures a consistent UI state (e.g., keeping buttons disabled after orientation change).
**Action:** Always make terminal-like commands copyable with visual feedback (Toast) and use `onSaveInstanceState` to persist UI states derived from irreversible native operations.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@

import androidx.appcompat.app.AppCompatActivity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.bytedance.shadowhook.ShadowHook;
import com.bytedance.shadowhook.systest.SysTest;
Expand All @@ -46,6 +54,39 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if (savedInstanceState != null) {
hookee2Loaded = savedInstanceState.getBoolean("hookee2Loaded", false);
if (hookee2Loaded) {
updateLoadButton();
}
}
}

@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean("hookee2Loaded", hookee2Loaded);
}

private void updateLoadButton() {
Button btn = findViewById(R.id.unitTestLoad);
if (btn != null) {
btn.setEnabled(false);
btn.setText(R.string.lib_loaded);
}
}

public void onAdbCommandClick(View view) {
if (view instanceof TextView) {
CharSequence text = ((TextView) view).getText();
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("ADB Command", text);
if (clipboard != null) {
clipboard.setPrimaryClip(clip);
Toast.makeText(this, R.string.adb_command_copied, Toast.LENGTH_SHORT).show();
}
}
}

public void onUnitTestHookSymAddrClick(View view) {
Expand All @@ -64,6 +105,7 @@ public void onUnitTestLoadClick(View view) {
if(!hookee2Loaded) {
hookee2Loaded = true;
System.loadLibrary("hookee2");
updateLoadButton();
}
}

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
android:orientation="vertical">

<TextView style="@style/Theme.TextView.Top"
android:text="adb logcat -b main -s shadowhook_tag" />
android:id="@+id/adbCommand"
android:text="adb logcat -b main -s shadowhook_tag"
android:onClick="onAdbCommandClick"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:contentDescription="@string/adb_command_content_description" />

<TextView style="@style/Theme.TextView.Title"
android:text="1. unit test" />
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<resources>
<string name="app_name">shadowhook</string>
</resources>
<string name="adb_command_copied">ADB command copied to clipboard</string>
<string name="adb_command_content_description">Copy ADB logcat command</string>
<string name="lib_loaded">libhookee2.so loaded</string>
</resources>
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ android.useAndroidX=true
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
#android.prefabVersion=2.0.0
android.disableAutomaticComponentCreation=true