Update survey triggering mechanisms

Settings will send the Settings screen to a central decision-making
place instead of each page handling its own.

Bug: 236662190
Test: robotest, manual

Change-Id: Ibfbdd421c723158d8d317aa4a02d9b51f877316a
This commit is contained in:
Binyi Wu
2022-07-22 15:33:19 +08:00
parent 08345933df
commit d43ecab8f7
3 changed files with 31 additions and 129 deletions

View File

@@ -16,14 +16,12 @@
package com.android.settings.survey;
import android.app.Activity;
import android.content.BroadcastReceiver;
import androidx.fragment.app.Fragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.overlay.SurveyFeatureProvider;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
/**
@@ -31,17 +29,17 @@ import com.android.settingslib.core.lifecycle.events.OnResume;
* in settings. This allows new classes to automatically support settings provided the extend
* one of the relevant classes in com.android.settings.lifecycle.
*/
public class SurveyMixin implements LifecycleObserver, OnResume, OnPause {
public class SurveyMixin implements LifecycleObserver, OnResume {
private String mName;
private Fragment mFragment;
private BroadcastReceiver mReceiver;
/**
* A mixin that attempts to perform survey related tasks right before onResume is called
* in a Settings PreferenceFragment. This will allow for remote updating and creation of
* surveys.
* @param fragment The fragment that this mixin will be attached to.
*
* @param fragment The fragment that this mixin will be attached to.
* @param fragmentName The simple name of the fragment.
*/
public SurveyMixin(Fragment fragment, String fragmentName) {
@@ -53,31 +51,13 @@ public class SurveyMixin implements LifecycleObserver, OnResume, OnPause {
public void onResume() {
Activity activity = mFragment.getActivity();
// guard against the activity not existing yet or the feature being disabled
// guard against the activity not existing yet
if (activity != null) {
SurveyFeatureProvider provider =
FeatureFactory.getFactory(activity).getSurveyFeatureProvider(activity);
if (provider != null) {
// Try to download a survey if there is none available, show the survey otherwise
String id = provider.getSurveyId(activity, mName);
if (provider.getSurveyExpirationDate(activity, id) <= -1) {
// register the receiver to show the survey on completion.
mReceiver = provider.createAndRegisterReceiver(activity);
provider.downloadSurvey(activity, id, null /* data */);
} else {
provider.showSurveyIfAvailable(activity, id);
}
provider.sendActivityIfAvailable(mName);
}
}
}
@Override
public void onPause() {
Activity activity = mFragment.getActivity();
if (mReceiver != null && activity != null) {
SurveyFeatureProvider.unregisterReceiver(activity, mReceiver);
mReceiver = null;
}
}
}