Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
muthuraj.mr committed Oct 21, 2022
0 parents commit 181fcb4
Show file tree
Hide file tree
Showing 32 changed files with 1,453 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches

# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
USB Debugging Quick Tile - toggle USB Debugging settings on Android 9/10 from the comfort of your quick settings panel

Inspired from https://github.com/joshuawolfsohn/Private-DNS-Quick-Tile
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
21 changes: 21 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 33
defaultConfig {
applicationId "com.muthuraj57.usbdebugging"
minSdkVersion 28
targetSdkVersion 33
versionCode 6
versionName '1.5'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
44 changes: 44 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:toolsNs="http://schemas.android.com/tools"
package="com.muthuraj57.usbdebugging">

<uses-permission
android:name="android.permission.WRITE_SECURE_SETTINGS"
toolsNs:ignore="ProtectedPermissions" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name="com.muthuraj57.usbdebugging.USBDebuggingConfigActivity"
android:excludeFromRecents="true"
android:exported="true"
android:label="@string/app_config">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>

<service
android:name="com.muthuraj57.usbdebugging.USBDebuggingTileService"
android:enabled="true"
android:exported="true"
android:icon="@drawable/ic_debugging_on"
android:label="@string/qt_default"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>

</application>

</manifest>
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.muthuraj57.usbdebugging;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.VideoView;

public class USBDebuggingConfigActivity extends Activity {

public static final int ADB_SETTING_ON = 1;
public static final int ADB_SETTING_OFF = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_usb_debugging_config);

final SharedPreferences togglestates = getSharedPreferences("togglestates", Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = togglestates.edit();

final CheckBox checkon = findViewById(R.id.check_on);

if ((!hasPermission()) || togglestates.getBoolean("first_run", true)) {
HelpMenu();
editor.putBoolean("first_run", false).apply();
return;
}

try {
int status = Settings.Global.getInt(getContentResolver(), Settings.Global.ADB_ENABLED);
togglestates.edit()
.putBoolean("toggle_on", status == ADB_SETTING_ON)
.apply();
} catch (Settings.SettingNotFoundException e) {
throw new RuntimeException(e);
}

if (togglestates.getBoolean("toggle_on", true)) {
checkon.setChecked(true);
}

checkon.setOnCheckedChangeListener((buttonView, isChecked) -> {
editor.putBoolean("toggle_on", checkon.isChecked());
int status;
if (isChecked) {
status = ADB_SETTING_ON;
} else {
status = ADB_SETTING_OFF;
}
Settings.Global.putInt(getContentResolver(), "adb_enabled", status);
});

}

public boolean hasPermission() {
return checkCallingOrSelfPermission("android.permission.WRITE_SECURE_SETTINGS") != PackageManager.PERMISSION_DENIED;
}

public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_overflow, menu);
return true;
}

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {

int id = item.getItemId();
if (id == R.id.action_appinfo) {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
} else if (id == R.id.action_help) {
HelpMenu();
}
return super.onMenuItemSelected(featureId, item);
}

public void HelpMenu() {
LayoutInflater layoutInflater = LayoutInflater.from(USBDebuggingConfigActivity.this);
View helpView = layoutInflater.inflate(R.layout.dialog_help, null);

VideoView videoView = helpView.findViewById(R.id.videoView);
videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.terminal));
videoView.start();

AlertDialog helpDialog = new AlertDialog
.Builder(USBDebuggingConfigActivity.this)
.setMessage(R.string.message_help)
.setPositiveButton(android.R.string.ok, null)
.setNeutralButton("Copy shell command", (dialog, which) -> {
String command = "pm grant com.muthuraj57.usbdebugging android.permission.WRITE_SECURE_SETTINGS";
getSystemService(ClipboardManager.class)
.setPrimaryClip(ClipData.newPlainText("Shell command", command));
})
.setView(helpView)
.create();
helpDialog.show();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.muthuraj57.usbdebugging;

import android.content.pm.PackageManager;
import android.graphics.drawable.Icon;
import android.provider.Settings;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import android.widget.Toast;

public class USBDebuggingTileService extends TileService {

public void onTileAdded() {
super.onTileAdded();

}

public void onTileRemoved() {
super.onTileRemoved();
}

public void onStartListening() {
super.onStartListening();

if (hasPermission()) {
int status;
try {
status = Settings.Global.getInt(getContentResolver(), Settings.Global.ADB_ENABLED);
} catch (Settings.SettingNotFoundException e) {
throw new RuntimeException(e);
}
Tile tile = this.getQsTile();

if (status == USBDebuggingConfigActivity.ADB_SETTING_ON) {
refreshTile(tile, Tile.STATE_ACTIVE, getString(R.string.debugging_on), R.drawable.ic_debugging_on);
} else {
refreshTile(tile, Tile.STATE_INACTIVE, getString(R.string.debugging_off), R.drawable.ic_debugging_off);
}
} else {
Toast.makeText(this, getString(R.string.toast_no_permission), Toast.LENGTH_SHORT).show();
}
}

public void onStopListening() {
super.onStopListening();
}

public void onClick() {
super.onClick();

if (hasPermission()) {
int status;
try {
status = Settings.Global.getInt(getContentResolver(), Settings.Global.ADB_ENABLED);
} catch (Settings.SettingNotFoundException e) {
throw new RuntimeException(e);
}

Tile tile = this.getQsTile();
if (status == USBDebuggingConfigActivity.ADB_SETTING_ON) {
changeTileState(tile, Tile.STATE_INACTIVE, getString(R.string.debugging_off), R.drawable.ic_debugging_off, USBDebuggingConfigActivity.ADB_SETTING_OFF);
} else {
changeTileState(tile, Tile.STATE_ACTIVE, getString(R.string.debugging_on), R.drawable.ic_debugging_on, USBDebuggingConfigActivity.ADB_SETTING_ON);
}

} else {
Toast.makeText(this, getString(R.string.toast_no_permission), Toast.LENGTH_SHORT).show();
}
}

public boolean hasPermission() {
return checkCallingOrSelfPermission("android.permission.WRITE_SECURE_SETTINGS") != PackageManager.PERMISSION_DENIED;
}

public void changeTileState(Tile tile, int state, String label, int icon, int status) {
tile.setLabel(label);
tile.setState(state);
tile.setIcon(Icon.createWithResource(this, icon));
Settings.Global.putInt(getContentResolver(), Settings.Global.ADB_ENABLED, status);
tile.updateTile();
}

public void refreshTile(Tile tile, int state, String label, int icon) {
tile.setState(state);
tile.setLabel(label);
tile.setIcon(Icon.createWithResource(this, icon));
tile.updateTile();
}


}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_debugging_off.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M15,8h4v4h-1v2c0,0.34 -0.08,0.66 -0.23,0.94L16,13.17V12h-1V8zM11,8.17l2,2V6h2l-3,-4L9,6h2V8.17zM13,16v2.28c0.6,0.34 1,0.98 1,1.72c0,1.1 -0.9,2 -2,2s-2,-0.9 -2,-2c0,-0.74 0.4,-1.37 1,-1.72V16H8c-1.11,0 -2,-0.89 -2,-2v-2.28C5.4,11.38 5,10.74 5,10c0,-0.59 0.26,-1.13 0.68,-1.49L1.39,4.22l1.41,-1.41l18.38,18.38l-1.41,1.41L13.17,16H13zM11,14v-0.17l-2.51,-2.51c-0.14,0.16 -0.31,0.29 -0.49,0.4V14H11z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_debugging_on.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#000000"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M15,7v4h1v2h-3V5h2l-3,-4 -3,4h2v8H8v-2.07c0.7,-0.37 1.2,-1.08 1.2,-1.93 0,-1.21 -0.99,-2.2 -2.2,-2.2 -1.21,0 -2.2,0.99 -2.2,2.2 0,0.85 0.5,1.56 1.2,1.93V13c0,1.11 0.89,2 2,2h3v3.05c-0.71,0.37 -1.2,1.1 -1.2,1.95 0,1.22 0.99,2.2 2.2,2.2 1.21,0 2.2,-0.98 2.2,-2.2 0,-0.85 -0.49,-1.58 -1.2,-1.95V15h3c1.11,0 2,-0.89 2,-2v-2h1V7h-4z" />
</vector>
Loading

0 comments on commit 181fcb4

Please sign in to comment.