From 3706b53e65d1fdd0e3ad199991dda3a17bf4ecbc Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Thu, 22 Sep 2016 16:47:54 -0500 Subject: [PATCH] WIP sync --- app/src/main/AndroidManifest.xml | 50 ++++++++++--------- .../com/topjohnwu/magisk/RootFragment.java | 2 + .../magisk/services/MonitorService.java | 2 +- .../magisk/services/TileServiceCompat.java | 6 +-- .../com/topjohnwu/magisk/utils/Utils.java | 30 +++++++++-- 5 files changed, 59 insertions(+), 31 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 06805420f..5076d15ea 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,16 +1,18 @@ - - - - - + package="com.topjohnwu.magisk"> + + + + + + + + tools:ignore="ProtectedPermissions" /> - + + android:resource="@xml/accessibilityservice" /> - + @@ -46,9 +48,9 @@ android:enabled="true" android:exported="true"> - - - + + + @@ -57,9 +59,9 @@ android:configChanges="orientation|screenSize" android:exported="true"> - + - + - + - - + + - + @@ -86,12 +88,12 @@ android:grantUriPermissions="true" android:permission="android.permission.MANAGE_DOCUMENTS"> - + + android:theme="@style/AppTheme.Transparent" /> + android:resource="@xml/file_paths" /> - + diff --git a/app/src/main/java/com/topjohnwu/magisk/RootFragment.java b/app/src/main/java/com/topjohnwu/magisk/RootFragment.java index 095a3270b..1ca1f9e9b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/RootFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/RootFragment.java @@ -19,6 +19,7 @@ import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.Switch; import android.widget.TextView; +import android.widget.Toast; import com.topjohnwu.magisk.receivers.Receiver; import com.topjohnwu.magisk.services.MonitorService; @@ -113,6 +114,7 @@ public class RootFragment extends Fragment implements Receiver { autoRootToggle.setOnClickListener(toggle -> { if (!Utils.hasServicePermission(getActivity())) { Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS); + Toast.makeText(getActivity(),"Please enable accessibility access for Magisk's auto-toggle feature to work.", Toast.LENGTH_LONG).show(); startActivityForResult(intent, 100); } else { ToggleAutoRoot(autoRootToggle.isChecked()); diff --git a/app/src/main/java/com/topjohnwu/magisk/services/MonitorService.java b/app/src/main/java/com/topjohnwu/magisk/services/MonitorService.java index 93a72b714..468a6154c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/services/MonitorService.java +++ b/app/src/main/java/com/topjohnwu/magisk/services/MonitorService.java @@ -68,7 +68,7 @@ public class MonitorService extends AccessibilityService { ActivityInfo activityInfo = tryGetActivity(componentName); boolean isActivity = activityInfo != null; if (isActivity) { - Log.i("Magisk", "CurrentActivity: " + componentName.getPackageName()); + Logger.dh("MonitorService: CurrentActivity: " + componentName.getPackageName()); String mPackage = componentName.getPackageName(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); diff --git a/app/src/main/java/com/topjohnwu/magisk/services/TileServiceCompat.java b/app/src/main/java/com/topjohnwu/magisk/services/TileServiceCompat.java index ab9bd71a4..a26a5f476 100644 --- a/app/src/main/java/com/topjohnwu/magisk/services/TileServiceCompat.java +++ b/app/src/main/java/com/topjohnwu/magisk/services/TileServiceCompat.java @@ -21,9 +21,9 @@ public class TileServiceCompat extends Service { private static boolean root, autoRoot; - public static final String TILE_ID = "com.shovelgrill.magiskmmtile.TILE"; - public static final String ACTION_TILE_CLICK = "com.shovelgrill.magiskmmtile.ACTION_TILE_CLICK"; - public static final String EXTRA_CLICK_TYPE = "com.shovelgrill.magiskmmtile.EXTRA_CLICK_TYPE"; + public static final String TILE_ID = "Magisk"; + public static final String ACTION_TILE_CLICK = "magisk.ACTION_TILE_CLICK"; + public static final String EXTRA_CLICK_TYPE = "magisk.EXTRA_CLICK_TYPE"; public static final int CLICK_TYPE_UNKNOWN = -1; public static final int CLICK_TYPE_SIMPLE = 0; public static final int CLICK_TYPE_LONG = 1; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index f7e965470..066a3599d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -266,11 +266,19 @@ public class Utils { } public static void installTile(Context context) { + String qsTileId; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + qsTileId = "custom(com.topjohnwu.magisk/.services.TileServiceNewApi)"; + } else { + qsTileId = "intent(Magisk)"; + } - String qsTileId = "intent(" + TileServiceCompat.TILE_ID + ")"; List lines = Shell.su("settings get secure sysui_qs_tiles"); if (lines != null && lines.size() == 1) { List tiles = new LinkedList(Arrays.asList(lines.get(0).split(","))); + List tiles2; + int tileSpace = Math.round(tiles.size()/2); + Logger.dh("Utils: Current Tile String is "+ tiles); if (tiles.size() > 1) { for (String tile : tiles) { if (tile.equals(qsTileId)) { @@ -278,9 +286,15 @@ public class Utils { return; } } + + tiles.add(tiles.size() + 1, qsTileId); String newTiles = TextUtils.join(",", tiles); + Logger.dh("Utils: NewtilesString is "+ newTiles); Shell.su("settings put secure sysui_qs_tiles \"" + newTiles + "\""); Toast.makeText(context, "Tile installed", Toast.LENGTH_SHORT).show(); + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { + Utils.refreshService(context); + } return; } } @@ -290,7 +304,12 @@ public class Utils { public static void uninstallTile(Context context) { - String qsTileId = "intent(" + TileServiceCompat.TILE_ID + ")"; + String qsTileId; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + qsTileId = "custom(com.topjohnwu.magisk/.services.TileServiceNewApi)"; + } else { + qsTileId = "intent(Magisk)"; + } List lines = Shell.su("settings get secure sysui_qs_tiles"); if (lines != null && lines.size() == 1) { List tiles = new LinkedList(Arrays.asList(lines.get(0).split(","))); @@ -307,6 +326,9 @@ public class Utils { String newTiles = TextUtils.join(",", tiles); Shell.su("settings put secure sysui_qs_tiles \"" + newTiles + "\""); Toast.makeText(context, "Tile uninstalled", Toast.LENGTH_SHORT).show(); + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { + Utils.refreshService(context); + } return; } Toast.makeText(context, "Tile already uninstalled", Toast.LENGTH_SHORT).show(); @@ -318,7 +340,9 @@ public class Utils { } - private void refreshService(Context context) { + + + private static void refreshService(Context context) { context.startService(new Intent(context, TileServiceCompat.class)); }