Skip to content

Commit

Permalink
Fix array out of bounds
Browse files Browse the repository at this point in the history
- Compatible with methods that are not deprecation in Android Oreo
  • Loading branch information
MlgmXyysd committed Apr 2, 2020
1 parent babbae4 commit 9d5404e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
minSdkVersion 24
//noinspection OldTargetApi
targetSdkVersion 27
versionCode 45600
versionCode 45601
versionName "4.5.6"
//noinspection GroovyAccessibility
project.ext.set("archivesBaseName", "EdXposedManager-" + versionName + "-" + versionCode + "-" + applicationId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class WelcomeActivity extends XposedBaseActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ThemeUtil.setTheme(this);
new ApplicationListAdapter(getApplicationContext(), AppHelper.isWhiteListMode()).generateCheckedList();
setContentView(R.layout.activity_welcome);

mDrawerLayout = findViewById(R.id.drawer_layout);
Expand Down Expand Up @@ -110,6 +109,8 @@ public void onDrawerSlide(View drawerView, float slideOffset) {

notifyDataSetChanged();

new Thread(() -> new ApplicationListAdapter(getApplicationContext(), AppHelper.isWhiteListMode()).generateCheckedList());

}

@Override
Expand Down
43 changes: 42 additions & 1 deletion app/src/main/java/org/meowcat/edxposed/manager/XposedApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Environment;
import android.os.FileUtils;
Expand All @@ -34,6 +38,7 @@
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Locale;
Expand All @@ -42,6 +47,7 @@
import de.robv.android.xposed.installer.util.InstallZipUtil;

import static org.meowcat.edxposed.manager.MeowCatApplication.TAG;
import static org.meowcat.edxposed.manager.adapter.AppHelper.FORCE_WHITE_LIST_MODULE;

@SuppressLint("Registered")
public class XposedApp extends de.robv.android.xposed.installer.XposedApp implements ActivityLifecycleCallbacks {
Expand Down Expand Up @@ -117,6 +123,7 @@ public static int getColor(Context context) {
return prefs.getInt("colors", defaultColor);
}

@SuppressWarnings("deprecation")
public static void setColors(ActionBar actionBar, Integer value, Activity activity) {
int color = value;
SharedPreferences prefs = activity.getSharedPreferences(activity.getPackageName() + "_preferences", MODE_PRIVATE);
Expand All @@ -127,7 +134,9 @@ public static void setColors(ActionBar actionBar, Integer value, Activity activi
actionBar.setBackgroundDrawable(new ColorDrawable(color));

ActivityManager.TaskDescription tDesc = new ActivityManager.TaskDescription(activity.getString(R.string.app_name),
drawable, color);
drawableToBitmap(activity.getDrawable(drawable)), color);
// ActivityManager.TaskDescription tDesc = new ActivityManager.TaskDescription(activity.getString(R.string.app_name),
// drawable, color);
activity.setTaskDescription(tDesc);

if (getPreferences().getBoolean("nav_bar", false)) {
Expand All @@ -138,6 +147,28 @@ public static void setColors(ActionBar actionBar, Integer value, Activity activi
}
}

public static Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap;

if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}

if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
}

Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}

/**
* @author PeterCxy https://github.com/PeterCxy/Lolistat/blob/aide/app/src/
* main/java/info/papdt/lolistat/support/Utility.java
Expand Down Expand Up @@ -190,6 +221,16 @@ public void onCreate() {

mPref = PreferenceManager.getDefaultSharedPreferences(this);

if (mPref.getBoolean("hook_modules", true)) {
Collection<ModuleUtil.InstalledModule> installedModules = ModuleUtil.getInstance().getModules().values();
for (ModuleUtil.InstalledModule info : installedModules) {
if (!FORCE_WHITE_LIST_MODULE.contains(info.packageName)) {
FORCE_WHITE_LIST_MODULE.add(info.packageName);
}
}
Log.d(MeowCatApplication.TAG, "ApplicationList: Force add modules to list");
}

de.robv.android.xposed.installer.XposedApp.getInstance().reloadXposedProp();
createDirectories();
delete(new File(Environment.getExternalStorageDirectory() + "/Download/EdXposedManager/.temp"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class AppHelper {

private static final List<String> FORCE_WHITE_LIST = new ArrayList<>(Collections.singletonList(BuildConfig.APPLICATION_ID));
private static final List<String> SAFETYNET_BLACK_LIST = new ArrayList<>(Arrays.asList("com.google.android.gms", "com.google.android.gsf"));
static List<String> FORCE_WHITE_LIST_MODULE = new ArrayList<>(FORCE_WHITE_LIST);
public static List<String> FORCE_WHITE_LIST_MODULE = new ArrayList<>(FORCE_WHITE_LIST);

static void makeSurePath() {
XposedApp.mkdirAndChmod(WHITE_LIST_PATH, rwxrwxrwx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@

import org.meowcat.edxposed.manager.MeowCatApplication;
import org.meowcat.edxposed.manager.R;
import org.meowcat.edxposed.manager.XposedApp;
import org.meowcat.edxposed.manager.util.ModuleUtil;

import java.util.Collection;
import java.util.List;

import static org.meowcat.edxposed.manager.adapter.AppHelper.FORCE_WHITE_LIST_MODULE;

public class ApplicationListAdapter extends AppAdapter {

private volatile boolean isWhiteListMode;
Expand All @@ -33,13 +28,6 @@ public ApplicationListAdapter(Context context, boolean isWhiteListMode) {

@Override
public List<String> generateCheckedList() {
if (XposedApp.getPreferences().getBoolean("hook_modules", true)) {
Collection<ModuleUtil.InstalledModule> installedModules = ModuleUtil.getInstance().getModules().values();
for (ModuleUtil.InstalledModule info : installedModules) {
FORCE_WHITE_LIST_MODULE.add(info.packageName);
}
Log.d(MeowCatApplication.TAG, "ApplicationList -> generateCheckedList: Force add modules to list");
}
AppHelper.makeSurePath();
if (isWhiteListMode) {
checkedList = AppHelper.getWhiteList();
Expand Down

0 comments on commit 9d5404e

Please sign in to comment.