Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to enable/disable ADB Wi-Fi #591

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" tools:ignore="ProtectedPermissions"/>

<!-- This permission is not used, but a permission is needed on the sharedfiles contentprovider,
which will always use FLAG_GRANT_READ_URI_PERMISSION. -->
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/termux/api/TermuxApiReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.provider.Settings;
import android.widget.Toast;

import com.termux.api.apis.AdbWifiAPI;
import com.termux.api.apis.AudioAPI;
import com.termux.api.apis.BatteryStatusAPI;
import com.termux.api.apis.BrightnessAPI;
Expand Down Expand Up @@ -264,6 +265,11 @@ private void doWork(Context context, Intent intent) {
case "WifiEnable":
WifiAPI.onReceiveWifiEnable(this, context, intent);
break;
case "AdbWifiEnable":
if (TermuxApiPermissionActivity.checkAndRequestPermissions(context, intent, Manifest.permission.WRITE_SECURE_SETTINGS)) {
AdbWifiAPI.onReceive(this, context, intent);
}
break;
default:
Logger.logError(LOG_TAG, "Unrecognized 'api_method' extra: '" + apiMethod + "'");
}
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/com/termux/api/apis/AdbWifiAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.termux.api.apis;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import com.termux.api.TermuxApiReceiver;
import com.termux.api.util.ResultReturner;
import com.termux.shared.logger.Logger;

public class AdbWifiAPI {

private static final String LOG_TAG = "AdbWifiAPI";

public static void onReceive(final TermuxApiReceiver receiver, final Context context, final Intent intent) {
Logger.logDebug(LOG_TAG, "onReceive");

final ContentResolver contentResolver = context.getContentResolver();

boolean enabled = intent.getBooleanExtra("enabled", true);

Settings.Global.putInt(contentResolver, "adb_wifi_enabled", enabled?1:0);

ResultReturner.noteDone(receiver, intent);
}
}