Merge "Fix App Compatibility Settings' lifecycle" am: 0ba498b226
am: 7e7924bf35
am: 0f1547cb76
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/2010296 Change-Id: I5a281e84d4c009fb0af9238f49a2e98dc9a7d17b
This commit is contained in:
@@ -31,6 +31,7 @@ import android.graphics.drawable.Drawable;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
@@ -66,6 +67,8 @@ public class PlatformCompatDashboard extends DashboardFragment {
|
|||||||
|
|
||||||
private AndroidBuildClassifier mAndroidBuildClassifier = new AndroidBuildClassifier();
|
private AndroidBuildClassifier mAndroidBuildClassifier = new AndroidBuildClassifier();
|
||||||
|
|
||||||
|
private boolean mShouldStartAppPickerOnResume = true;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
String mSelectedApp;
|
String mSelectedApp;
|
||||||
|
|
||||||
@@ -98,13 +101,67 @@ public class PlatformCompatDashboard extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onCreate(icicle);
|
||||||
try {
|
try {
|
||||||
mChanges = getPlatformCompat().listUIChanges();
|
mChanges = getPlatformCompat().listUIChanges();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw new RuntimeException("Could not list changes!", e);
|
throw new RuntimeException("Could not list changes!", e);
|
||||||
}
|
}
|
||||||
|
if (icicle != null) {
|
||||||
|
mShouldStartAppPickerOnResume = false;
|
||||||
|
mSelectedApp = icicle.getString(COMPAT_APP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (requestCode == REQUEST_COMPAT_CHANGE_APP) {
|
||||||
|
mShouldStartAppPickerOnResume = false;
|
||||||
|
switch (resultCode) {
|
||||||
|
case Activity.RESULT_OK:
|
||||||
|
mSelectedApp = data.getAction();
|
||||||
|
break;
|
||||||
|
case Activity.RESULT_CANCELED:
|
||||||
|
if (TextUtils.isEmpty(mSelectedApp)) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case AppPicker.RESULT_NO_MATCHING_APPS:
|
||||||
|
mSelectedApp = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
if (isFinishingOrDestroyed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!mShouldStartAppPickerOnResume) {
|
||||||
|
if (TextUtils.isEmpty(mSelectedApp)) {
|
||||||
|
new AlertDialog.Builder(getContext())
|
||||||
|
.setTitle(R.string.platform_compat_dialog_title_no_apps)
|
||||||
|
.setMessage(R.string.platform_compat_dialog_text_no_apps)
|
||||||
|
.setPositiveButton(R.string.okay, (dialog, which) -> finish())
|
||||||
|
.setOnDismissListener(dialog -> finish())
|
||||||
|
.setCancelable(false)
|
||||||
|
.show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
final ApplicationInfo applicationInfo = getApplicationInfo();
|
||||||
|
addPreferences(applicationInfo);
|
||||||
|
return;
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
mShouldStartAppPickerOnResume = true;
|
||||||
|
mSelectedApp = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
startAppPicker();
|
startAppPicker();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,31 +171,6 @@ public class PlatformCompatDashboard extends DashboardFragment {
|
|||||||
outState.putString(COMPAT_APP, mSelectedApp);
|
outState.putString(COMPAT_APP, mSelectedApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
if (requestCode == REQUEST_COMPAT_CHANGE_APP) {
|
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
|
||||||
mSelectedApp = data.getAction();
|
|
||||||
try {
|
|
||||||
final ApplicationInfo applicationInfo = getApplicationInfo();
|
|
||||||
addPreferences(applicationInfo);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
startAppPicker();
|
|
||||||
}
|
|
||||||
} else if (resultCode == AppPicker.RESULT_NO_MATCHING_APPS) {
|
|
||||||
new AlertDialog.Builder(getContext())
|
|
||||||
.setTitle(R.string.platform_compat_dialog_title_no_apps)
|
|
||||||
.setMessage(R.string.platform_compat_dialog_text_no_apps)
|
|
||||||
.setPositiveButton(R.string.okay, (dialog, which) -> finish())
|
|
||||||
.setOnDismissListener(dialog -> finish())
|
|
||||||
.setCancelable(false)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addPreferences(ApplicationInfo applicationInfo) {
|
private void addPreferences(ApplicationInfo applicationInfo) {
|
||||||
getPreferenceScreen().removeAll();
|
getPreferenceScreen().removeAll();
|
||||||
getPreferenceScreen().addPreference(createAppPreference(applicationInfo));
|
getPreferenceScreen().addPreference(createAppPreference(applicationInfo));
|
||||||
|
Reference in New Issue
Block a user