Merge changes from topic "feedback_and_help" into main
* changes: Hide "Send feedback" button if no target exists. Move "Send feedback" button to the end of the list
This commit is contained in:
committed by
Android (Google) Code Review
commit
22e56834fd
@@ -19,9 +19,12 @@ package com.android.settings.datetime;
|
||||
import static android.content.Intent.URI_INTENT_SCHEME;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
@@ -40,17 +43,22 @@ public class TimeFeedbackPreferenceController
|
||||
extends BasePreferenceController
|
||||
implements PreferenceControllerMixin {
|
||||
|
||||
private static final String TAG = "TimeFeedbackController";
|
||||
|
||||
private final PackageManager mPackageManager;
|
||||
private final String mIntentUri;
|
||||
private final int mAvailabilityStatus;
|
||||
|
||||
public TimeFeedbackPreferenceController(Context context, String preferenceKey) {
|
||||
this(context, preferenceKey, context.getResources().getString(
|
||||
this(context, context.getPackageManager(), preferenceKey, context.getResources().getString(
|
||||
R.string.config_time_feedback_intent_uri));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
TimeFeedbackPreferenceController(Context context, String preferenceKey, String intentUri) {
|
||||
TimeFeedbackPreferenceController(Context context, PackageManager packageManager,
|
||||
String preferenceKey, String intentUri) {
|
||||
super(context, preferenceKey);
|
||||
mPackageManager = packageManager;
|
||||
mIntentUri = intentUri;
|
||||
mAvailabilityStatus = TextUtils.isEmpty(mIntentUri) ? UNSUPPORTED_ON_DEVICE : AVAILABLE;
|
||||
}
|
||||
@@ -70,6 +78,9 @@ public class TimeFeedbackPreferenceController
|
||||
if (!DateTimeLaunchUtils.isFeedbackFeatureSupported()) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
if (!isTimeFeedbackTargetAvailable()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
return mAvailabilityStatus;
|
||||
}
|
||||
|
||||
@@ -89,7 +100,25 @@ public class TimeFeedbackPreferenceController
|
||||
mContext.startActivity(intent);
|
||||
return true;
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException("Bad intent configuration: " + mIntentUri, e);
|
||||
Log.e(TAG, "Bad intent configuration: " + mIntentUri, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTimeFeedbackTargetAvailable() {
|
||||
Intent intent;
|
||||
try {
|
||||
intent = Intent.parseUri(mIntentUri, URI_INTENT_SCHEME);
|
||||
} catch (URISyntaxException e) {
|
||||
Log.e(TAG, "Bad intent configuration: " + mIntentUri, e);
|
||||
return false;
|
||||
}
|
||||
ComponentName resolvedActivity = intent.resolveActivity(mPackageManager);
|
||||
|
||||
if (resolvedActivity == null) {
|
||||
Log.w(TAG, "No valid target for the time feedback intent: " + intent);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user