[Settings] Fix crash when user enter bluetooth page quickly.
- When SliceManager try to pinSlice, process may not have the permssion yet, so in Androix lib it use try/catch to avoid Security exception. However, if SliceManger quickly unpinSlice after pinSlice, process may still not get the permission yet, then due to no security exception, it cause the settings crash. Bug: 283065718 Test: atest passed Test: Manual test passed Change-Id: I2293fca73e65dfaa34237abe57e0c6a3fe0f62bb
This commit is contained in:
@@ -113,15 +113,27 @@ public class BlockingPrefWithSliceController extends BasePreferenceController im
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (mLiveData != null) {
|
||||
if (mLiveData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
mLiveData.observeForever(this);
|
||||
} catch (SecurityException e) {
|
||||
Log.w(TAG, "observeForever - no permission");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mLiveData != null) {
|
||||
if (mLiveData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
mLiveData.removeObserver(this);
|
||||
} catch (SecurityException e) {
|
||||
Log.w(TAG, "removeObserver - no permission");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -44,7 +44,6 @@ public class SlicePreferenceController extends BasePreferenceController implemen
|
||||
LiveData<Slice> mLiveData;
|
||||
@VisibleForTesting
|
||||
SlicePreference mSlicePreference;
|
||||
private boolean mIsObservering = false;
|
||||
private Uri mUri;
|
||||
|
||||
public SlicePreferenceController(Context context, String preferenceKey) {
|
||||
@@ -74,9 +73,14 @@ public class SlicePreferenceController extends BasePreferenceController implemen
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (mLiveData != null && !mIsObservering) {
|
||||
mIsObservering = true;
|
||||
if (mLiveData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
mLiveData.observeForever(this);
|
||||
} catch (SecurityException e) {
|
||||
Log.w(TAG, "observeForever - no permission");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,9 +95,14 @@ public class SlicePreferenceController extends BasePreferenceController implemen
|
||||
}
|
||||
|
||||
private void removeLiveDataObserver() {
|
||||
if (mLiveData != null && mIsObservering && mLiveData.hasActiveObservers()) {
|
||||
mIsObservering = false;
|
||||
if (mLiveData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
mLiveData.removeObserver(this);
|
||||
} catch (SecurityException e) {
|
||||
Log.w(TAG, "removeLiveDataObserver - no permission");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user