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() {
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());
}

View File

@ -180,13 +180,19 @@ public class RepoItemFragment extends BaseFragment implements RepoLoader.Listene
.build());
try {
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 charset = contentTypes.length > 1 ? contentTypes[1].split("=\\s*")[1] : "utf-8";
var body = reply.body();
if (body == null) return null;
return new WebResourceResponse(
mimeType,
charset,
reply.body().byteStream()
body.byteStream()
);
} catch (Throwable e) {
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 entries = new ArrayList<CharSequence>();
entries.add(language.getEntries()[0]);
var lstLang = getAppLanguages(getContext(), R.string.Settings);
var lstLang = getAppLanguages(requireContext(), R.string.Settings);
for (var lang : lstLang) {
var locale = Locale.forLanguageTag(lang);
entries.add(HtmlCompat.fromHtml(String.format("%s - %s",

View File

@ -57,7 +57,7 @@ public class LinkifyTextView extends androidx.appcompat.widget.AppCompatTextView
@SuppressLint("ClickableViewAccessibility")
@Override
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
// do not contain a url, the TextView will still get MotionEvent.
// 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 =
new Parcelable.Creator<SavedState>() {
new Parcelable.Creator<>() {
@Override
public SavedState createFromParcel(Parcel 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);
if (intent == null) {
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) {
if (activityInfo.processName.equals(activityInfo.packageName)) {
intent = new Intent();
@ -177,10 +177,12 @@ public class LSPManagerService extends ILSPManagerService.Stub {
}
}
}
if (intent.getCategories() != null) intent.getCategories().clear();
intent.addCategory("org.lsposed.manager.LAUNCH_MANAGER");
intent.setPackage(BuildConfig.MANAGER_INJECTED_PKG_NAME);
managerIntent = (Intent) intent.clone();
if (intent != null && intent.getCategories() != null) {
intent.getCategories().clear();
intent.addCategory("org.lsposed.manager.LAUNCH_MANAGER");
intent.setPackage(BuildConfig.MANAGER_INJECTED_PKG_NAME);
managerIntent = (Intent) intent.clone();
}
}
} catch (Throwable e) {
Log.e(TAG, "get Intent", e);
@ -322,7 +324,10 @@ public class LSPManagerService extends ILSPManagerService.Stub {
private void ensureWebViewPermission() {
try {
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 httpCacheDir = new File(cacheDir, "http_cache");
ensureWebViewPermission(webviewDir);
@ -630,8 +635,10 @@ public class LSPManagerService extends ILSPManagerService.Stub {
args.putString("value", hide ? "0" : "1");
args.putString("_user", "0");
try {
ActivityManagerService.getContentProvider("settings", 0)
.call("android", null, "settings", "PUT_global", "show_hidden_icon_apps_enabled", args);
var contentProvider = ActivityManagerService.getContentProvider("settings", 0);
if (contentProvider != null) {
contentProvider.call("android", null, "settings", "PUT_global", "show_hidden_icon_apps_enabled", args);
}
} catch (RemoteException | NullPointerException e) {
Log.w(TAG, "setHiddenIcon: ", e);
}

View File

@ -40,17 +40,22 @@ public class MetaDataReader {
}
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"));
byte[] bytes = getBytesFromInputStream(is);
AxmlReader reader = new AxmlReader(bytes);
reader.accept(new AxmlVisitor() {
@Override
public NodeVisitor child(String ns, String name) {
NodeVisitor child = super.child(ns, name);
return new ManifestTagVisitor(child);
}
});
byte[] bytes = getBytesFromInputStream(is);
AxmlReader reader = null;
if (bytes != null) {
reader = new AxmlReader(bytes);
}
if (reader != null) {
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) {
bos.write(b, 0, n);
}
byte[] data = bos.toByteArray();
return data;
return bos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
}
@ -91,7 +95,7 @@ public class MetaDataReader {
@Override
public NodeVisitor child(String ns, String name) {
NodeVisitor child = super.child(ns, name);
if("meta-data".equals(name)) {
if ("meta-data".equals(name)) {
return new MetaDataVisitor(child);
}
return child;
@ -102,6 +106,7 @@ public class MetaDataReader {
private class MetaDataVisitor extends NodeVisitor {
public String name = null;
public Object value = null;
public MetaDataVisitor(NodeVisitor child) {
super(child);
}
@ -109,9 +114,9 @@ public class MetaDataReader {
@Override
public void attr(String ns, String name, int resourceId, int type, Object obj) {
if (type == 3 && "name".equals(name)) {
this.name = (String)obj;
this.name = (String) obj;
}
if ("value".equals(name) ) {
if ("value".equals(name)) {
value = obj;
}
super.attr(ns, name, resourceId, type, obj);
@ -119,7 +124,7 @@ public class MetaDataReader {
@Override
public void end() {
if(name != null && value != null) {
if (name != null && value != null) {
metaData.put(name, value);
}
super.end();

View File

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