2016-08-22 21:18:28 +00:00
|
|
|
package com.topjohnwu.magisk.utils;
|
2016-08-22 19:50:46 +00:00
|
|
|
|
2016-08-28 22:35:07 +00:00
|
|
|
import android.Manifest;
|
|
|
|
import android.app.Activity;
|
2016-09-16 04:46:10 +00:00
|
|
|
import android.app.ActivityManager;
|
2016-08-28 22:35:07 +00:00
|
|
|
import android.app.DownloadManager;
|
|
|
|
import android.content.BroadcastReceiver;
|
2016-08-27 19:52:03 +00:00
|
|
|
import android.content.Context;
|
2016-08-28 22:35:07 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2016-09-21 12:39:12 +00:00
|
|
|
import android.content.SharedPreferences;
|
2016-08-28 22:35:07 +00:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.net.Uri;
|
2016-09-20 16:36:33 +00:00
|
|
|
import android.os.Build;
|
2016-08-28 22:35:07 +00:00
|
|
|
import android.os.Environment;
|
2016-09-20 05:05:41 +00:00
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.provider.Settings;
|
2016-08-28 22:35:07 +00:00
|
|
|
import android.support.design.widget.Snackbar;
|
|
|
|
import android.support.v4.app.ActivityCompat;
|
2016-09-20 05:05:41 +00:00
|
|
|
import android.text.TextUtils;
|
2016-09-08 20:47:10 +00:00
|
|
|
import android.util.Base64;
|
2016-09-01 21:58:26 +00:00
|
|
|
import android.util.Log;
|
2016-08-28 22:35:07 +00:00
|
|
|
import android.view.View;
|
2016-08-27 19:52:03 +00:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
2016-09-20 16:36:33 +00:00
|
|
|
import com.kcoppock.broadcasttilesupport.BroadcastTileIntentBuilder;
|
2016-08-27 19:52:03 +00:00
|
|
|
import com.topjohnwu.magisk.R;
|
2016-09-21 12:39:12 +00:00
|
|
|
import com.topjohnwu.magisk.RootFragment;
|
2016-09-21 14:22:36 +00:00
|
|
|
import com.topjohnwu.magisk.module.BaseModule;
|
2016-09-21 12:39:12 +00:00
|
|
|
import com.topjohnwu.magisk.receivers.PrivateBroadcastReceiver;
|
2016-09-20 16:36:33 +00:00
|
|
|
import com.topjohnwu.magisk.services.MonitorService;
|
|
|
|
import com.topjohnwu.magisk.services.QuickSettingTileService;
|
2016-09-21 21:55:20 +00:00
|
|
|
import com.topjohnwu.magisk.services.TileService;
|
2016-08-27 19:52:03 +00:00
|
|
|
|
2016-08-28 22:35:07 +00:00
|
|
|
import java.io.File;
|
2016-09-08 20:47:10 +00:00
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.security.InvalidKeyException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.security.spec.InvalidKeySpecException;
|
2016-09-21 21:55:20 +00:00
|
|
|
import java.util.Arrays;
|
2016-09-21 14:22:36 +00:00
|
|
|
import java.util.Comparator;
|
2016-09-21 21:55:20 +00:00
|
|
|
import java.util.LinkedList;
|
2016-08-22 08:09:36 +00:00
|
|
|
import java.util.List;
|
2016-08-20 15:26:49 +00:00
|
|
|
|
2016-09-08 20:47:10 +00:00
|
|
|
import javax.crypto.BadPaddingException;
|
|
|
|
import javax.crypto.Cipher;
|
|
|
|
import javax.crypto.IllegalBlockSizeException;
|
|
|
|
import javax.crypto.NoSuchPaddingException;
|
|
|
|
import javax.crypto.SecretKey;
|
|
|
|
import javax.crypto.SecretKeyFactory;
|
|
|
|
import javax.crypto.spec.DESKeySpec;
|
|
|
|
|
2016-08-20 15:26:49 +00:00
|
|
|
public class Utils {
|
|
|
|
|
2016-08-28 22:35:07 +00:00
|
|
|
public static int magiskVersion, remoteMagiskVersion = -1, remoteAppVersion = -1;
|
2016-09-20 22:01:20 +00:00
|
|
|
public static String magiskLink, magiskChangelog, appChangelog, appLink, phhLink, supersuLink;
|
2016-09-08 19:47:04 +00:00
|
|
|
private static final String TAG = "Magisk";
|
2016-08-28 22:35:07 +00:00
|
|
|
|
2016-09-20 22:01:20 +00:00
|
|
|
public static final String MAGISK_PATH = "/magisk";
|
|
|
|
public static final String MAGISK_CACHE_PATH = "/cache/magisk";
|
|
|
|
public static final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/updates/magisk_update.json";
|
2016-08-28 22:35:07 +00:00
|
|
|
|
2016-09-21 14:22:36 +00:00
|
|
|
public static void init(Context context) {
|
|
|
|
List<String> ret = Shell.sh("getprop magisk.version");
|
|
|
|
if (ret.get(0).replaceAll("\\s", "").isEmpty()) {
|
|
|
|
magiskVersion = -1;
|
|
|
|
} else {
|
|
|
|
magiskVersion = Integer.parseInt(ret.get(0));
|
|
|
|
}
|
|
|
|
if (!Shell.rootAccess()) {
|
|
|
|
Snackbar.make(((Activity) context).findViewById(android.R.id.content), R.string.no_root_access, Snackbar.LENGTH_LONG).show();
|
|
|
|
}
|
2016-09-21 21:55:20 +00:00
|
|
|
if (PrefHelper.CheckBool("keep_root_off")) {
|
|
|
|
Utils.toggleRoot(false);
|
|
|
|
}
|
|
|
|
if (PrefHelper.CheckBool("enable_quicktile")) {
|
|
|
|
Utils.SetupQuickSettingsTile(context);
|
|
|
|
}
|
2016-09-21 14:22:36 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:58:15 +00:00
|
|
|
public static boolean fileExist(String path) {
|
|
|
|
List<String> ret;
|
2016-09-17 18:32:08 +00:00
|
|
|
String command = "if [ -f " + path + " ]; then echo true; else echo false; fi";
|
|
|
|
if (Shell.rootAccess()) {
|
|
|
|
ret = Shell.su(command);
|
|
|
|
} else {
|
|
|
|
ret = Shell.sh(command);
|
|
|
|
}
|
|
|
|
return Boolean.parseBoolean(ret.get(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean rootEnabled() {
|
|
|
|
List<String> ret;
|
|
|
|
String command = "if [ -z $(which su) ]; then echo false; else echo true; fi";
|
|
|
|
ret = Shell.sh(command);
|
2016-08-24 21:58:15 +00:00
|
|
|
return Boolean.parseBoolean(ret.get(0));
|
2016-08-22 17:44:34 +00:00
|
|
|
}
|
|
|
|
|
2016-09-20 05:05:41 +00:00
|
|
|
public static boolean autoRootEnabled(Context context) {
|
2016-09-21 12:39:12 +00:00
|
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
Log.d("Magisk", "AutoRootEnableCheck is " + preferences.getBoolean("autoRootEnable", false));
|
|
|
|
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("autoRootEnable", false);
|
2016-09-20 05:05:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-24 21:58:15 +00:00
|
|
|
public static boolean createFile(String path) {
|
2016-09-17 18:32:08 +00:00
|
|
|
String command = "touch " + path + " 2>/dev/null; if [ -f " + path + " ]; then echo true; else echo false; fi";
|
2016-08-24 21:58:15 +00:00
|
|
|
if (!Shell.rootAccess()) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2016-09-17 18:32:08 +00:00
|
|
|
return Boolean.parseBoolean(Shell.su(command).get(0));
|
2016-08-24 21:58:15 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-20 15:26:49 +00:00
|
|
|
|
2016-08-24 21:58:15 +00:00
|
|
|
public static boolean removeFile(String path) {
|
2016-09-17 18:32:08 +00:00
|
|
|
String command = "rm -f " + path + " 2>/dev/null; if [ -f " + path + " ]; then echo false; else echo true; fi";
|
2016-08-24 21:58:15 +00:00
|
|
|
if (!Shell.rootAccess()) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2016-09-17 18:32:08 +00:00
|
|
|
return Boolean.parseBoolean(Shell.su(command).get(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void toggleRoot(Boolean b) {
|
2016-09-21 12:39:12 +00:00
|
|
|
if (Utils.magiskVersion != -1) {
|
|
|
|
if (b) {
|
|
|
|
Shell.su("ln -s $(getprop magisk.supath) /magisk/.core/bin", "setprop magisk.root 1");
|
|
|
|
} else {
|
|
|
|
Shell.su("rm -rf /magisk/.core/bin", "setprop magisk.root 0");
|
|
|
|
}
|
2016-08-20 15:26:49 +00:00
|
|
|
}
|
2016-08-24 21:58:15 +00:00
|
|
|
}
|
2016-08-22 08:09:36 +00:00
|
|
|
|
2016-09-20 05:05:41 +00:00
|
|
|
public static void toggleAutoRoot(Boolean b, Context context) {
|
2016-09-21 12:39:12 +00:00
|
|
|
if (Utils.magiskVersion != -1) {
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("autoRootEnable", b).apply();
|
|
|
|
Intent myServiceIntent = new Intent(context, MonitorService.class);
|
|
|
|
if (b) {
|
|
|
|
context.startService(myServiceIntent);
|
|
|
|
} else {
|
|
|
|
context.stopService(myServiceIntent);
|
|
|
|
}
|
2016-09-20 05:05:41 +00:00
|
|
|
}
|
2016-09-21 12:39:12 +00:00
|
|
|
UpdateRootFragmentUI(context);
|
2016-09-20 05:05:41 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:58:15 +00:00
|
|
|
public static List<String> getModList(String path) {
|
|
|
|
List<String> ret;
|
2016-09-21 14:22:36 +00:00
|
|
|
String command = "find " + path + " -type d -maxdepth 1 ! -name \"*.core\" ! -name \"*lost+found\" ! -name \"*magisk\"";
|
|
|
|
if (Shell.rootAccess()) {
|
|
|
|
ret = Shell.su(command);
|
|
|
|
} else {
|
|
|
|
ret = Shell.sh(command);
|
|
|
|
}
|
2016-08-24 21:58:15 +00:00
|
|
|
return ret;
|
2016-08-20 15:26:49 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:58:15 +00:00
|
|
|
public static List<String> readFile(String path) {
|
|
|
|
List<String> ret;
|
2016-09-21 14:22:36 +00:00
|
|
|
String command = "cat " + path;
|
|
|
|
if (Shell.rootAccess()) {
|
|
|
|
ret = Shell.su(command);
|
|
|
|
} else {
|
|
|
|
ret = Shell.sh(command);
|
|
|
|
}
|
2016-08-24 21:58:15 +00:00
|
|
|
return ret;
|
2016-08-22 17:44:34 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 22:35:07 +00:00
|
|
|
public static void downloadAndReceive(Context context, DownloadReceiver receiver, String link, String file) {
|
|
|
|
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
Toast.makeText(context, R.string.permissionNotGranted, Toast.LENGTH_LONG).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
File downloadFile, dir = new File(Environment.getExternalStorageDirectory() + "/MagiskManager");
|
|
|
|
downloadFile = new File(dir + "/" + file);
|
|
|
|
if (!dir.exists()) dir.mkdir();
|
|
|
|
if (downloadFile.exists()) downloadFile.delete();
|
|
|
|
|
|
|
|
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
|
|
|
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(link));
|
|
|
|
request.setDestinationUri(Uri.fromFile(downloadFile));
|
|
|
|
|
|
|
|
receiver.setDownloadID(downloadManager.enqueue(request));
|
|
|
|
context.registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
|
|
|
}
|
|
|
|
|
2016-09-17 18:32:08 +00:00
|
|
|
public static String procFile(String value, Context context) {
|
|
|
|
|
|
|
|
String cryptoPass = context.getResources().getString(R.string.pass);
|
|
|
|
try {
|
|
|
|
DESKeySpec keySpec = new DESKeySpec(cryptoPass.getBytes("UTF8"));
|
|
|
|
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
|
|
|
|
SecretKey key = keyFactory.generateSecret(keySpec);
|
|
|
|
|
|
|
|
byte[] encrypedPwdBytes = Base64.decode(value, Base64.DEFAULT);
|
|
|
|
// cipher is not thread safe
|
|
|
|
Cipher cipher = Cipher.getInstance("DES");
|
|
|
|
cipher.init(Cipher.DECRYPT_MODE, key);
|
|
|
|
byte[] decrypedValueBytes = (cipher.doFinal(encrypedPwdBytes));
|
|
|
|
|
|
|
|
return new String(decrypedValueBytes);
|
|
|
|
|
|
|
|
} catch (InvalidKeyException | UnsupportedEncodingException | NoSuchAlgorithmException
|
|
|
|
| BadPaddingException | NoSuchPaddingException | IllegalBlockSizeException
|
|
|
|
| InvalidKeySpecException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2016-09-20 16:36:33 +00:00
|
|
|
public static void SetupQuickSettingsTile(Context mContext) {
|
2016-09-21 21:55:20 +00:00
|
|
|
Logger.dh("Utils: SetupQuickSettings called");
|
2016-09-20 16:36:33 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
|
Intent serviceIntent = new Intent(mContext, QuickSettingTileService.class);
|
|
|
|
mContext.startService(serviceIntent);
|
|
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
|
2016-09-21 21:55:20 +00:00
|
|
|
Logger.dh("Utils: Marshmallow build detected");
|
2016-09-20 16:36:33 +00:00
|
|
|
String mLabelString;
|
2016-09-21 12:39:12 +00:00
|
|
|
int mRootIcon = R.drawable.root_white;
|
|
|
|
int mAutoRootIcon = R.drawable.ic_autoroot_white;
|
|
|
|
int mRootDisabled = R.drawable.root_grey;
|
2016-09-20 16:36:33 +00:00
|
|
|
int mRootsState = CheckRootsState(mContext);
|
2016-09-21 21:55:20 +00:00
|
|
|
Logger.dh("Utils: Root State returned as " + mRootsState);
|
2016-09-20 16:36:33 +00:00
|
|
|
final Intent enableBroadcast = new Intent(PrivateBroadcastReceiver.ACTION_ENABLEROOT);
|
|
|
|
final Intent disableBroadcast = new Intent(PrivateBroadcastReceiver.ACTION_DISABLEROOT);
|
|
|
|
final Intent autoBroadcast = new Intent(PrivateBroadcastReceiver.ACTION_AUTOROOT);
|
|
|
|
Intent intent;
|
2016-09-21 12:39:12 +00:00
|
|
|
|
2016-09-20 16:36:33 +00:00
|
|
|
int mIcon;
|
|
|
|
switch (mRootsState) {
|
|
|
|
case 2:
|
|
|
|
mLabelString = "Auto-root";
|
|
|
|
mIcon = mAutoRootIcon;
|
|
|
|
intent = autoBroadcast;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
mLabelString = "Root enabled";
|
|
|
|
mIcon = mRootIcon;
|
2016-09-21 12:39:12 +00:00
|
|
|
intent = disableBroadcast;
|
2016-09-20 16:36:33 +00:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
mLabelString = "Root disabled";
|
2016-09-21 12:39:12 +00:00
|
|
|
mIcon = mRootDisabled;
|
|
|
|
intent = enableBroadcast;
|
2016-09-20 16:36:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
2016-09-21 12:39:12 +00:00
|
|
|
mLabelString = "Root disabled";
|
|
|
|
mIcon = mRootDisabled;
|
|
|
|
intent = disableBroadcast;
|
2016-09-20 16:36:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-21 12:39:12 +00:00
|
|
|
Intent tileConfigurationIntent = new BroadcastTileIntentBuilder(mContext, "Magisk")
|
2016-09-20 16:36:33 +00:00
|
|
|
.setLabel(mLabelString)
|
|
|
|
.setIconResource(mIcon)
|
|
|
|
.setOnClickBroadcast(intent)
|
2016-09-21 12:39:12 +00:00
|
|
|
.setOnLongClickBroadcast(autoBroadcast)
|
|
|
|
.setVisible(true)
|
2016-09-20 16:36:33 +00:00
|
|
|
.build();
|
|
|
|
mContext.sendBroadcast(tileConfigurationIntent);
|
2016-09-21 12:39:12 +00:00
|
|
|
|
2016-09-20 16:36:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-21 21:55:20 +00:00
|
|
|
public static void installTile(Context context) {
|
|
|
|
|
|
|
|
String qsTileId = "intent(" + TileService.TILE_ID + ")";
|
|
|
|
List<String> lines = Shell.su("settings get secure sysui_qs_tiles");
|
|
|
|
if (lines != null && lines.size() == 1) {
|
|
|
|
List<String> tiles = new LinkedList<String>(Arrays.asList(lines.get(0).split(",")));
|
|
|
|
if (tiles.size() > 1) {
|
|
|
|
for (String tile : tiles) {
|
|
|
|
if (tile.equals(qsTileId)) {
|
|
|
|
Toast.makeText(context, "Tile already installed", Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String newTiles = TextUtils.join(",", tiles);
|
|
|
|
Shell.su("settings put secure sysui_qs_tiles \"" + newTiles + "\"");
|
|
|
|
Toast.makeText(context, "Tile installed", Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Toast.makeText(context, "Tile installation error", Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void uninstallTile(Context context) {
|
|
|
|
|
|
|
|
String qsTileId = "intent(" + TileService.TILE_ID + ")";
|
|
|
|
List<String> lines = Shell.su("settings get secure sysui_qs_tiles");
|
|
|
|
if (lines != null && lines.size() == 1) {
|
|
|
|
List<String> tiles = new LinkedList<String>(Arrays.asList(lines.get(0).split(",")));
|
|
|
|
if (tiles.size() > 1) {
|
|
|
|
boolean isPresent = false;
|
|
|
|
for (int i = 0; i < tiles.size(); i++) {
|
|
|
|
if (tiles.get(i).equals(qsTileId)) {
|
|
|
|
isPresent = true;
|
|
|
|
tiles.remove(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isPresent) {
|
|
|
|
String newTiles = TextUtils.join(",", tiles);
|
|
|
|
Shell.su("settings put secure sysui_qs_tiles \"" + newTiles + "\"");
|
|
|
|
Toast.makeText(context, "Tile uninstalled", Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Toast.makeText(context, "Tile already uninstalled", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Toast.makeText(context, "Tile uninstallation error", Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void refreshService(Context context) {
|
|
|
|
context.startService(new Intent(context, TileService.class));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-21 12:39:12 +00:00
|
|
|
public static void UpdateRootFragmentUI(Context context) {
|
|
|
|
|
2016-09-21 21:55:20 +00:00
|
|
|
Logger.dh("Magisk", "Utils: UpdateRF called");
|
2016-09-21 12:39:12 +00:00
|
|
|
Intent intent = new Intent(context, RootFragment.class);
|
|
|
|
intent.setAction("com.magisk.UPDATEUI");
|
|
|
|
context.sendBroadcast(intent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-20 16:36:33 +00:00
|
|
|
// Gets an overall state for the quick settings tile
|
|
|
|
// 0 for root disabled, 1 for root enabled (no auto), 2 for auto-root
|
|
|
|
|
|
|
|
public static int CheckRootsState(Context mContext) {
|
|
|
|
if (autoRootEnabled(mContext)) {
|
|
|
|
return 2;
|
|
|
|
} else {
|
2016-09-20 22:01:20 +00:00
|
|
|
if (rootEnabled()) {
|
2016-09-20 16:36:33 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-20 05:05:41 +00:00
|
|
|
// To check if service is enabled
|
|
|
|
public static boolean hasServicePermission(Context mContext) {
|
|
|
|
int accessibilityEnabled = 0;
|
|
|
|
final String service = mContext.getPackageName() + "/" + MonitorService.class.getCanonicalName();
|
|
|
|
try {
|
|
|
|
accessibilityEnabled = Settings.Secure.getInt(
|
|
|
|
mContext.getApplicationContext().getContentResolver(),
|
|
|
|
android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
|
|
|
|
} catch (Settings.SettingNotFoundException e) {
|
|
|
|
Log.e(TAG, "Error finding setting, default accessibility to not found: "
|
|
|
|
+ e.getMessage());
|
|
|
|
}
|
|
|
|
TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
|
|
|
|
|
|
|
|
if (accessibilityEnabled == 1) {
|
|
|
|
String settingValue = Settings.Secure.getString(
|
|
|
|
mContext.getApplicationContext().getContentResolver(),
|
|
|
|
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
|
|
|
|
if (settingValue != null) {
|
|
|
|
mStringColonSplitter.setString(settingValue);
|
|
|
|
while (mStringColonSplitter.hasNext()) {
|
|
|
|
String accessibilityService = mStringColonSplitter.next();
|
|
|
|
|
|
|
|
if (accessibilityService.equalsIgnoreCase(service)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-09-19 21:48:13 +00:00
|
|
|
}
|
2016-09-20 05:05:41 +00:00
|
|
|
} else {
|
|
|
|
Log.v(TAG, "***ACCESSIBILITY IS DISABLED***");
|
2016-09-19 06:46:07 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 21:48:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-28 22:35:07 +00:00
|
|
|
public abstract static class DownloadReceiver extends BroadcastReceiver {
|
|
|
|
public Context mContext;
|
|
|
|
long downloadID;
|
|
|
|
public String mName;
|
|
|
|
|
2016-09-11 18:36:58 +00:00
|
|
|
public DownloadReceiver() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public DownloadReceiver(String name) {
|
|
|
|
mName = name;
|
|
|
|
}
|
2016-08-28 22:35:07 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
mContext = context;
|
|
|
|
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
|
|
|
String action = intent.getAction();
|
2016-09-11 18:36:58 +00:00
|
|
|
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
|
2016-08-28 22:35:07 +00:00
|
|
|
DownloadManager.Query query = new DownloadManager.Query();
|
|
|
|
query.setFilterById(downloadID);
|
|
|
|
Cursor c = downloadManager.query(query);
|
|
|
|
if (c.moveToFirst()) {
|
|
|
|
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
|
|
|
|
int status = c.getInt(columnIndex);
|
|
|
|
switch (status) {
|
|
|
|
case DownloadManager.STATUS_SUCCESSFUL:
|
|
|
|
File file = new File(Uri.parse(c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))).getPath());
|
|
|
|
task(file);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Toast.makeText(context, R.string.download_file_error, Toast.LENGTH_LONG).show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
context.unregisterReceiver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-11 18:36:58 +00:00
|
|
|
public void setDownloadID(long id) {
|
|
|
|
downloadID = id;
|
|
|
|
}
|
|
|
|
|
2016-08-28 22:35:07 +00:00
|
|
|
public abstract void task(File file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-16 04:46:10 +00:00
|
|
|
public static boolean isMyServiceRunning(Class<?> serviceClass, Context context) {
|
|
|
|
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
|
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
|
|
|
if (serviceClass.getName().equals(service.service.getClassName())) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-20 05:05:41 +00:00
|
|
|
}
|
2016-09-16 04:46:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-21 14:22:36 +00:00
|
|
|
public interface ItemClickListener {
|
2016-09-11 18:36:58 +00:00
|
|
|
|
2016-09-21 14:22:36 +00:00
|
|
|
void onItemClick(View view, int position);
|
2016-09-12 21:47:32 +00:00
|
|
|
|
2016-09-11 18:36:58 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 14:22:36 +00:00
|
|
|
public static class ModuleComparator implements Comparator<BaseModule> {
|
2016-09-11 18:36:58 +00:00
|
|
|
@Override
|
2016-09-21 14:22:36 +00:00
|
|
|
public int compare(BaseModule o1, BaseModule o2) {
|
|
|
|
return o1.getName().compareTo(o2.getName());
|
2016-08-28 22:35:07 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-21 14:22:36 +00:00
|
|
|
}
|