Detect system framework injection status (#619)

This commit is contained in:
LoveSy 2021-05-18 14:25:06 +08:00 committed by GitHub
parent 0cb223afea
commit fd32c3107a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 48 additions and 5 deletions

View File

@ -254,4 +254,12 @@ public class ConfigManager {
return Arrays.stream(System.getenv("PATH").split(File.pathSeparator))
.anyMatch(str -> new File(str, "magisk").exists());
}
public static boolean systemServerRequested() {
try {
return LSPManagerServiceClient.systemServerRequested();
} catch (Throwable e) {
return false;
}
}
}

View File

@ -158,8 +158,14 @@ public class LSPManagerServiceClient {
ensureService();
return service.getUsers();
}
public static int installExistingPackageAsUser(String packageName, int userId) throws RemoteException, NullPointerException {
ensureService();
return service.installExistingPackageAsUser(packageName, userId);
}
public static boolean systemServerRequested() throws RemoteException, NullPointerException {
ensureService();
return service.systemServerRequested();
}
}

View File

@ -97,6 +97,11 @@ public class MainActivity extends BaseActivity {
cardBackgroundColor = ResourcesKt.resolveColor(getTheme(), R.attr.colorWarning);
binding.statusIcon.setImageResource(R.drawable.ic_warning);
binding.statusSummary.setText(R.string.selinux_policy_not_loaded_summary);
} else if (!ConfigManager.systemServerRequested()) {
binding.statusTitle.setText(R.string.partial_activated);
cardBackgroundColor = ResourcesKt.resolveColor(getTheme(), R.attr.colorWarning);
binding.statusIcon.setImageResource(R.drawable.ic_warning);
binding.statusSummary.setText(R.string.system_inject_fail_summary);
} else {
binding.statusTitle.setText(R.string.activated);
cardBackgroundColor = ResourcesKt.resolveColor(getTheme(), R.attr.colorNormal);

View File

@ -56,8 +56,11 @@ public class InfoDialogBuilder extends BlurBehindDialogBuilder {
binding.systemAbi.setText(Build.SUPPORTED_ABIS[0]);
if (!ConfigManager.isSepolicyLoaded()) {
binding.selinux.setVisibility(View.VISIBLE);
binding.selinux.setText(HtmlCompat.fromHtml(context.getString(R.string.selinux_policy_not_loaded), HtmlCompat.FROM_HTML_MODE_LEGACY));
binding.note.setVisibility(View.VISIBLE);
binding.note.setText(HtmlCompat.fromHtml(context.getString(R.string.selinux_policy_not_loaded), HtmlCompat.FROM_HTML_MODE_LEGACY));
} else if (!ConfigManager.systemServerRequested()) {
binding.note.setVisibility(View.VISIBLE);
binding.note.setText(HtmlCompat.fromHtml(context.getString(R.string.system_inject_fail), HtmlCompat.FROM_HTML_MODE_LEGACY));
}
setView(binding.getRoot());

View File

@ -105,11 +105,11 @@
android:layout_height="wrap_content" />
<TextView
android:id="@+id/selinux"
android:id="@+id/note"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:visibility="gone" />
</LinearLayout>
</rikka.widget.borderview.BorderNestedScrollView>
</rikka.widget.borderview.BorderNestedScrollView>

View File

@ -41,6 +41,8 @@
<string name="partial_activated">部分激活</string>
<string name="selinux_policy_not_loaded_summary">SEPolicy 未被正确加载</string>
<string name="selinux_policy_not_loaded"><![CDATA[<b>警告:</b>SEPolicy 未被正确加载,作用于系统框架的模块将不起作用。<br>请将此报告给 <a href="https://github.com/topjohnwu/Magisk/issues"><b>Magisk</b></a> 开发者。]]></string>
<string name="system_inject_fail_summary">系统框架注入失败</string>
<string name="system_inject_fail"><![CDATA[<b>警告:</b>系统注入失败。<br/>这是极罕见的情况,可能是由 <b>Magisk</b> 或低质 Magisk 模块导致。<br/>请尝试禁用除 Riru 和 LSPosed 外的 Magisk 模块,或向开发者提供完整日志。]]></string>
<string name="info_api_version">API 版本</string>
<string name="info_framework_version">框架版本</string>
<string name="info_manager_version">管理器版本</string>

View File

@ -40,7 +40,9 @@
<string name="not_installed">Not installed</string>
<string name="partial_activated">Partially activated</string>
<string name="selinux_policy_not_loaded_summary">SEPolicy is not loaded properly</string>
<string name="selinux_policy_not_loaded"><![CDATA[<b>WARNING:</b> SEPolicy is not loaded properly, modules that hook System Framework will not work.<br>Please report this to <a href="https://github.com/topjohnwu/Magisk/issues"><b>Magisk</b></a> developer.]]></string>
<string name="selinux_policy_not_loaded"><![CDATA[<b>WARNING:</b> SEPolicy is not loaded properly, modules that hook System Framework will not work.<br/>Please report this to <a href="https://github.com/topjohnwu/Magisk/issues"><b>Magisk</b></a> developer.]]></string>
<string name="system_inject_fail_summary">System Framework injection failed</string>
<string name="system_inject_fail"><![CDATA[<b>WARNING:</b> System Framework inject failed.<br/>This is rare and may be caused by <b>Magisk</b> or some low-quality Magisk modules.<br/>Please try to disable Magisk modules other than Riru and LSPosed or submit full log to developers.]]></string>
<string name="info_api_version">API version</string>
<string name="info_framework_version">Framework version</string>
<string name="info_manager_version">Manager version</string>

View File

@ -180,4 +180,9 @@ public class LSPManagerService extends ILSPManagerService.Stub {
return PackageService.INSTALL_FAILED_INTERNAL_ERROR;
}
}
@Override
public boolean systemServerRequested() throws RemoteException {
return ServiceManager.systemServerRequested();
}
}

View File

@ -15,6 +15,11 @@ public class LSPSystemServerService extends ILSPSystemServerService.Stub impleme
public static final String PROXY_SERVICE_NAME = "serial";
private IBinder originService = null;
private boolean requested = false;
public boolean systemServerRequested() {
return requested;
}
public void putBinderForSystemServer() {
android.os.ServiceManager.addService(PROXY_SERVICE_NAME, this);
@ -48,6 +53,7 @@ public class LSPSystemServerService extends ILSPSystemServerService.Stub impleme
@Override
public ILSPApplicationService requestApplicationService(int uid, int pid, String processName, IBinder heartBeat) throws RemoteException {
requested = true;
if (ConfigManager.getInstance().shouldSkipSystemServer() || uid != 1000 || heartBeat == null || !"android".equals(processName))
return null;
else
@ -77,5 +83,6 @@ public class LSPSystemServerService extends ILSPSystemServerService.Stub impleme
originService.unlinkToDeath(this, 0);
originService = null;
}
requested = false;
}
}

View File

@ -134,4 +134,7 @@ public class ServiceManager {
return managerService;
}
public static boolean systemServerRequested() {
return systemServerService.systemServerRequested();
}
}

View File

@ -50,4 +50,6 @@ interface ILSPManagerService {
int[] getUsers() = 27;
int installExistingPackageAsUser(String packageName, int userId) = 28;
boolean systemServerRequested() = 29;
}