Adapt to Android O new broadcast limitations

This commit is contained in:
topjohnwu 2017-07-01 18:06:23 +08:00
parent 789fef34ba
commit bf1f941e50
3 changed files with 23 additions and 13 deletions

View File

@ -62,8 +62,8 @@
<receiver android:name=".receivers.PackageReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>

View File

@ -1,12 +1,14 @@
package com.topjohnwu.magisk;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.widget.Toast;
@ -81,6 +83,7 @@ public class SettingsActivity extends Activity {
suNotification = (ListPreference) findPreference("su_notification");
multiuserMode = (ListPreference) findPreference("multiuser_mode");
namespaceMode = (ListPreference) findPreference("mnt_ns");
SwitchPreference reauth = (SwitchPreference) findPreference("su_reauth");
setSummary();
@ -90,6 +93,11 @@ public class SettingsActivity extends Activity {
prefScreen.removePreference(suCategory);
}
// Remove re-authentication option on Android O, it will not work
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
suCategory.removePreference(reauth);
}
findPreference("clear").setOnPreferenceClickListener((pref) -> {
Utils.clearRepoCache(getActivity());
return true;

View File

@ -20,20 +20,22 @@ public class PackageReceiver extends BroadcastReceiver {
return;
switch (intent.getAction()) {
case Intent.ACTION_PACKAGE_ADDED:
int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
// Update the UID if available
if (uid > 0) {
policy.uid = uid % 100000;
}
magiskManager.suDB.updatePolicy(policy);
return;
case Intent.ACTION_PACKAGE_REMOVED:
boolean isUpdate = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
if (!isUpdate || magiskManager.suReauth) {
case Intent.ACTION_PACKAGE_REPLACED:
// This will only work pre-O
if (magiskManager.suReauth) {
magiskManager.suDB.deletePolicy(policy);
} else {
int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
// Update the UID if available
if (uid > 0) {
policy.uid = uid % 100000;
}
magiskManager.suDB.updatePolicy(policy);
}
break;
case Intent.ACTION_PACKAGE_FULLY_REMOVED:
magiskManager.suDB.deletePolicy(policy);
break;
}
}
}