Require non null (#1193)

This commit is contained in:
Howard Wu 2021-09-30 14:15:19 +08:00 committed by GitHub
parent 862988be2a
commit d51fa92f82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 31 deletions

View File

@ -263,7 +263,9 @@ public class ConfigManager {
} }
public static boolean isMagiskInstalled() { public static boolean isMagiskInstalled() {
return Arrays.stream(System.getenv("PATH").split(File.pathSeparator)) var path = System.getenv("PATH");
if (path == null) return false;
else return Arrays.stream(path.split(File.pathSeparator))
.anyMatch(str -> new File(str, "magisk").exists()); .anyMatch(str -> new File(str, "magisk").exists());
} }

View File

@ -180,13 +180,19 @@ public class RepoItemFragment extends BaseFragment implements RepoLoader.Listene
.build()); .build());
try { try {
Response reply = call.execute(); Response reply = call.execute();
var contentTypes = reply.header("content-type", "image/*;charset=utf-8").split(";\\s*"); var header = reply.header("content-type", "image/*;charset=utf-8");
String[] contentTypes = new String[0];
if (header != null) {
contentTypes = header.split(";\\s*");
}
var mimeType = contentTypes.length > 0 ? contentTypes[0] : "image/*"; var mimeType = contentTypes.length > 0 ? contentTypes[0] : "image/*";
var charset = contentTypes.length > 1 ? contentTypes[1].split("=\\s*")[1] : "utf-8"; var charset = contentTypes.length > 1 ? contentTypes[1].split("=\\s*")[1] : "utf-8";
var body = reply.body();
if (body == null) return null;
return new WebResourceResponse( return new WebResourceResponse(
mimeType, mimeType,
charset, charset,
reply.body().byteStream() body.byteStream()
); );
} catch (Throwable e) { } catch (Throwable e) {
return new WebResourceResponse("text/html", "utf-8", new ByteArrayInputStream(Log.getStackTraceString(e).getBytes(StandardCharsets.UTF_8))); return new WebResourceResponse("text/html", "utf-8", new ByteArrayInputStream(Log.getStackTraceString(e).getBytes(StandardCharsets.UTF_8)));

View File

@ -255,7 +255,7 @@ public class SettingsFragment extends BaseFragment {
var userLocale = App.getLocale(); var userLocale = App.getLocale();
var entries = new ArrayList<CharSequence>(); var entries = new ArrayList<CharSequence>();
entries.add(language.getEntries()[0]); entries.add(language.getEntries()[0]);
var lstLang = getAppLanguages(getContext(), R.string.Settings); var lstLang = getAppLanguages(requireContext(), R.string.Settings);
for (var lang : lstLang) { for (var lang : lstLang) {
var locale = Locale.forLanguageTag(lang); var locale = Locale.forLanguageTag(lang);
entries.add(HtmlCompat.fromHtml(String.format("%s - %s", entries.add(HtmlCompat.fromHtml(String.format("%s - %s",

View File

@ -57,7 +57,7 @@ public class LinkifyTextView extends androidx.appcompat.widget.AppCompatTextView
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@Override @Override
public boolean onTouchEvent(@NonNull MotionEvent event) { public boolean onTouchEvent(@NonNull MotionEvent event) {
// Let the parent or grandparent of TextView to handles click aciton. // Let the parent or grandparent of TextView to handles click action.
// Otherwise click effect like ripple will not work, and if touch area // Otherwise click effect like ripple will not work, and if touch area
// do not contain a url, the TextView will still get MotionEvent. // do not contain a url, the TextView will still get MotionEvent.
// onTouchEven must be called with MotionEvent.ACTION_DOWN for each touch // onTouchEven must be called with MotionEvent.ACTION_DOWN for each touch

View File

@ -168,7 +168,7 @@ public class ThemeColorPreference extends DialogPreference {
} }
public static final Parcelable.Creator<SavedState> CREATOR = public static final Parcelable.Creator<SavedState> CREATOR =
new Parcelable.Creator<SavedState>() { new Parcelable.Creator<>() {
@Override @Override
public SavedState createFromParcel(Parcel in) { public SavedState createFromParcel(Parcel in) {
return new SavedState(in); return new SavedState(in);

View File

@ -166,7 +166,7 @@ public class LSPManagerService extends ILSPManagerService.Stub {
var intent = PackageService.getLaunchIntentForPackage(BuildConfig.MANAGER_INJECTED_PKG_NAME); var intent = PackageService.getLaunchIntentForPackage(BuildConfig.MANAGER_INJECTED_PKG_NAME);
if (intent == null) { if (intent == null) {
var pkgInfo = PackageService.getPackageInfo(BuildConfig.MANAGER_INJECTED_PKG_NAME, PackageManager.GET_ACTIVITIES, 0); var pkgInfo = PackageService.getPackageInfo(BuildConfig.MANAGER_INJECTED_PKG_NAME, PackageManager.GET_ACTIVITIES, 0);
if (pkgInfo.activities != null && pkgInfo.activities.length > 0) { if (pkgInfo != null && pkgInfo.activities != null && pkgInfo.activities.length > 0) {
for (var activityInfo : pkgInfo.activities) { for (var activityInfo : pkgInfo.activities) {
if (activityInfo.processName.equals(activityInfo.packageName)) { if (activityInfo.processName.equals(activityInfo.packageName)) {
intent = new Intent(); intent = new Intent();
@ -177,10 +177,12 @@ public class LSPManagerService extends ILSPManagerService.Stub {
} }
} }
} }
if (intent.getCategories() != null) intent.getCategories().clear(); if (intent != null && intent.getCategories() != null) {
intent.addCategory("org.lsposed.manager.LAUNCH_MANAGER"); intent.getCategories().clear();
intent.setPackage(BuildConfig.MANAGER_INJECTED_PKG_NAME); intent.addCategory("org.lsposed.manager.LAUNCH_MANAGER");
managerIntent = (Intent) intent.clone(); intent.setPackage(BuildConfig.MANAGER_INJECTED_PKG_NAME);
managerIntent = (Intent) intent.clone();
}
} }
} catch (Throwable e) { } catch (Throwable e) {
Log.e(TAG, "get Intent", e); Log.e(TAG, "get Intent", e);
@ -322,7 +324,10 @@ public class LSPManagerService extends ILSPManagerService.Stub {
private void ensureWebViewPermission() { private void ensureWebViewPermission() {
try { try {
var pkgInfo = PackageService.getPackageInfo(BuildConfig.MANAGER_INJECTED_PKG_NAME, 0, 0); var pkgInfo = PackageService.getPackageInfo(BuildConfig.MANAGER_INJECTED_PKG_NAME, 0, 0);
var cacheDir = new File(HiddenApiBridge.ApplicationInfo_credentialProtectedDataDir(pkgInfo.applicationInfo) + "/cache"); File cacheDir = null;
if (pkgInfo != null) {
cacheDir = new File(HiddenApiBridge.ApplicationInfo_credentialProtectedDataDir(pkgInfo.applicationInfo) + "/cache");
}
var webviewDir = new File(cacheDir, "WebView"); var webviewDir = new File(cacheDir, "WebView");
var httpCacheDir = new File(cacheDir, "http_cache"); var httpCacheDir = new File(cacheDir, "http_cache");
ensureWebViewPermission(webviewDir); ensureWebViewPermission(webviewDir);
@ -630,8 +635,10 @@ public class LSPManagerService extends ILSPManagerService.Stub {
args.putString("value", hide ? "0" : "1"); args.putString("value", hide ? "0" : "1");
args.putString("_user", "0"); args.putString("_user", "0");
try { try {
ActivityManagerService.getContentProvider("settings", 0) var contentProvider = ActivityManagerService.getContentProvider("settings", 0);
.call("android", null, "settings", "PUT_global", "show_hidden_icon_apps_enabled", args); if (contentProvider != null) {
contentProvider.call("android", null, "settings", "PUT_global", "show_hidden_icon_apps_enabled", args);
}
} catch (RemoteException | NullPointerException e) { } catch (RemoteException | NullPointerException e) {
Log.w(TAG, "setHiddenIcon: ", e); Log.w(TAG, "setHiddenIcon: ", e);
} }

View File

@ -40,17 +40,22 @@ public class MetaDataReader {
} }
private MetaDataReader(File apk) throws IOException { private MetaDataReader(File apk) throws IOException {
try(JarFile zip = new JarFile(apk)) { try (JarFile zip = new JarFile(apk)) {
InputStream is = zip.getInputStream(zip.getEntry("AndroidManifest.xml")); InputStream is = zip.getInputStream(zip.getEntry("AndroidManifest.xml"));
byte[] bytes = getBytesFromInputStream(is); byte[] bytes = getBytesFromInputStream(is);
AxmlReader reader = new AxmlReader(bytes); AxmlReader reader = null;
reader.accept(new AxmlVisitor() { if (bytes != null) {
@Override reader = new AxmlReader(bytes);
public NodeVisitor child(String ns, String name) { }
NodeVisitor child = super.child(ns, name); if (reader != null) {
return new ManifestTagVisitor(child); reader.accept(new AxmlVisitor() {
} @Override
}); public NodeVisitor child(String ns, String name) {
NodeVisitor child = super.child(ns, name);
return new ManifestTagVisitor(child);
}
});
}
} }
} }
@ -61,8 +66,7 @@ public class MetaDataReader {
while ((n = inputStream.read(b)) != -1) { while ((n = inputStream.read(b)) != -1) {
bos.write(b, 0, n); bos.write(b, 0, n);
} }
byte[] data = bos.toByteArray(); return bos.toByteArray();
return data;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -91,7 +95,7 @@ public class MetaDataReader {
@Override @Override
public NodeVisitor child(String ns, String name) { public NodeVisitor child(String ns, String name) {
NodeVisitor child = super.child(ns, name); NodeVisitor child = super.child(ns, name);
if("meta-data".equals(name)) { if ("meta-data".equals(name)) {
return new MetaDataVisitor(child); return new MetaDataVisitor(child);
} }
return child; return child;
@ -102,6 +106,7 @@ public class MetaDataReader {
private class MetaDataVisitor extends NodeVisitor { private class MetaDataVisitor extends NodeVisitor {
public String name = null; public String name = null;
public Object value = null; public Object value = null;
public MetaDataVisitor(NodeVisitor child) { public MetaDataVisitor(NodeVisitor child) {
super(child); super(child);
} }
@ -109,9 +114,9 @@ public class MetaDataReader {
@Override @Override
public void attr(String ns, String name, int resourceId, int type, Object obj) { public void attr(String ns, String name, int resourceId, int type, Object obj) {
if (type == 3 && "name".equals(name)) { if (type == 3 && "name".equals(name)) {
this.name = (String)obj; this.name = (String) obj;
} }
if ("value".equals(name) ) { if ("value".equals(name)) {
value = obj; value = obj;
} }
super.attr(ns, name, resourceId, type, obj); super.attr(ns, name, resourceId, type, obj);
@ -119,7 +124,7 @@ public class MetaDataReader {
@Override @Override
public void end() { public void end() {
if(name != null && value != null) { if (name != null && value != null) {
metaData.put(name, value); metaData.put(name, value);
} }
super.end(); super.end();

View File

@ -203,7 +203,9 @@ public class ParasiticManagerHooker {
try { try {
var webViewDelegateConstructor = WebViewDelegate.class.getDeclaredConstructor(); var webViewDelegateConstructor = WebViewDelegate.class.getDeclaredConstructor();
webViewDelegateConstructor.setAccessible(true); webViewDelegateConstructor.setAccessible(true);
sProviderInstance = staticFactory.invoke(null, webViewDelegateConstructor.newInstance()); if (staticFactory != null) {
sProviderInstance = staticFactory.invoke(null, webViewDelegateConstructor.newInstance());
}
XposedHelpers.setStaticObjectField(WebViewFactory.class, "sProviderInstance", sProviderInstance); XposedHelpers.setStaticObjectField(WebViewFactory.class, "sProviderInstance", sProviderInstance);
Hookers.logD("Loaded provider: " + sProviderInstance); Hookers.logD("Loaded provider: " + sProviderInstance);
return sProviderInstance; return sProviderInstance;