Add a couple of guards to make sure crash doesn't happen
This adds two guards, first checking when the provider list is generated to stop and flag an warning, second to have PackageMonitor use a handler so callbacks should only happen on the thread that the fragment is running on and if that is no longer available it won't do anything. Test: ondevice Bug: 296164461 Change-Id: Iab03f8a10e667694e2e23da7574831f9ea5c38e2
This commit is contained in:
@@ -28,6 +28,8 @@ import android.credentials.CredentialProviderInfo;
|
||||
import android.credentials.SetEnabledProvidersException;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.OutcomeReceiver;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
@@ -43,7 +45,6 @@ import com.android.internal.content.PackageMonitor;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.defaultapps.DefaultAppPickerFragment;
|
||||
import com.android.settingslib.applications.DefaultAppInfo;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
import com.android.settingslib.widget.CandidateInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -65,6 +66,8 @@ public class DefaultCombinedPicker extends DefaultAppPickerFragment {
|
||||
private CredentialManager mCredentialManager;
|
||||
private int mIntentSenderUserId = -1;
|
||||
|
||||
private static final Handler sMainHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -132,17 +135,44 @@ public class DefaultCombinedPicker extends DefaultAppPickerFragment {
|
||||
new PackageMonitor() {
|
||||
@Override
|
||||
public void onPackageAdded(String packageName, int uid) {
|
||||
ThreadUtils.postOnMainThread(() -> update());
|
||||
sMainHandler.post(
|
||||
() -> {
|
||||
// See b/296164461 for context
|
||||
if (getContext() == null) {
|
||||
Log.w(TAG, "context is null");
|
||||
return;
|
||||
}
|
||||
|
||||
update();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackageModified(String packageName) {
|
||||
ThreadUtils.postOnMainThread(() -> update());
|
||||
sMainHandler.post(
|
||||
() -> {
|
||||
// See b/296164461 for context
|
||||
if (getContext() == null) {
|
||||
Log.w(TAG, "context is null");
|
||||
return;
|
||||
}
|
||||
|
||||
update();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackageRemoved(String packageName, int uid) {
|
||||
ThreadUtils.postOnMainThread(() -> update());
|
||||
sMainHandler.post(
|
||||
() -> {
|
||||
// See b/296164461 for context
|
||||
if (getContext() == null) {
|
||||
Log.w(TAG, "context is null");
|
||||
return;
|
||||
}
|
||||
|
||||
update();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -275,10 +305,7 @@ public class DefaultCombinedPicker extends DefaultAppPickerFragment {
|
||||
protected CharSequence getConfirmationMessage(CandidateInfo appInfo) {
|
||||
// If we are selecting none then show a warning label.
|
||||
if (appInfo == null) {
|
||||
final String message =
|
||||
getContext()
|
||||
.getString(
|
||||
R.string.credman_confirmation_message);
|
||||
final String message = getContext().getString(R.string.credman_confirmation_message);
|
||||
return Html.fromHtml(message);
|
||||
}
|
||||
final CharSequence appName = appInfo.loadLabel();
|
||||
|
Reference in New Issue
Block a user