A concise Android application for controlling Airplane Mode, supporting two control methods: WRITE_SECURE_SETTINGS permission and Digital Assistant permission.
For detailed documentation and policy analysis, please visit: https://powerli2002.github.io/posts/appairplane/
- Manual Control: Toggle Airplane Mode on/off with a single tap.
- Smart Toggle: Checks the current state before toggling.
- Timed Toggle: Turns on Airplane Mode → waits 2 seconds → turns off Airplane Mode.
- Automatic Toggle: Automatically toggles Airplane Mode at a set interval.
- Permission Check: Automatically detects and prompts for permission configuration.
The most direct method. It controls system settings directly after granting the WRITE_SECURE_SETTINGS permission via ADB.
Authorization Command:
adb shell pm grant com.example.airplanecontrol android.permission.WRITE_SECURE_SETTINGSCharacteristics:
- The most direct control with the fastest response time.
- Performs well on the Android Studio emulator.
- May have compatibility issues on real devices.
This method bypasses system restrictions to control Airplane Mode by leveraging the Android Digital Assistant permission.
Configuration Steps:
- Open the app and tap the "Configure Permissions" button.
- Tap "Open Assistant Settings".
- Select "Airplane Mode Control Assistant" as the default digital assistant app.
- Return to the app; the permission status should now show as configured.
Characteristics:
- Better compatibility, suitable for real devices.
- Uses a system-level permission to control Airplane Mode.
- Configuration is slightly more complex, but it offers high stability.
This is achieved using a workaround: a background service launches a transparent Activity, which then uses the Activity's showAssist method to trigger the digital assistant to control Airplane Mode.
- Transparent Activity: An Activity with no visible UI, used solely to trigger
showAssist. - Lifecycle Control: The
showAssistmethod is triggered within theonWindowFocusChangedcallback. - Task Stack Management: Uses a separate task stack to avoid returning to the main UI.
- Background Service: A foreground service is used to ensure the toggle operation is executed reliably.
app/src/main/java/com/example/airplanecontrol/
├── ui/
│ ├── AirplaneModeActivity.java # Main UI Activity
│ └── TransparentActivity.java # Transparent Activity
├── services/
│ ├── AutoTaskService.java # Automatic Task Service
│ ├── MyInteractionService.java # Digital Assistant Interaction Service
│ └── MyInteractionSessionService.java # Session Service
├── utils/
│ └── AirplaneModeUtils.java # Utility class
├── AirplaneControlApplication.java # Main Application class
├── AppLifecycleObserver.java # Lifecycle Observer
└── BootCompletedReceiver.java # Boot Completed Receiver
Permissions required by the application:
BIND_VOICE_INTERACTION: For Digital Assistant functionality.WRITE_SETTINGS: To write to system settings.WRITE_SECURE_SETTINGS: To write to secure system settings (optional, granted via ADB).FOREGROUND_SERVICE: To run foreground services.POST_NOTIFICATIONS: To post notifications.FOREGROUND_SERVICE_DATA_SYNC: For data synchronization in a foreground service.
- Android Studio
- minSdkVersion: 24
- targetSdkVersion: 35
- Java 11
- Clone the project.
- Open it in Android Studio.
- Wait for the Gradle sync to complete.
- Connect a device or start an emulator.
- Click the "Run" button.
Configure permissions according to your chosen control method:
Method 1: ADB Grant (Recommended for development/testing)
adb shell pm grant com.example.airplanecontrol android.permission.WRITE_SECURE_SETTINGSMethod 2: Digital Assistant Configuration
- Install and open the application.
- Tap "Configure Permissions".
- Follow the prompts to set the app as the default digital assistant.
This project is for learning and research purposes only. Please comply with all relevant laws and regulations.