Set<String> getKeepEnabledPackages();
/**
+ * Returns a user readable text explaining how much time user has spent in an app at a
+ * pre-specified duration.
+ */
+ default CharSequence getTimeSpentInApp(String packageName) {
+ return null;
+ }
+
+ /**
* Callback that receives the number of packages installed on the device.
*/
interface NumberOfAppsCallback {
public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvider {
- private final Context mContext;
+ protected final Context mContext;
private final PackageManager mPm;
private final IPackageManager mPms;
private final DevicePolicyManager mDpm;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
+import com.android.settings.applications.ApplicationFeatureProvider;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.overlay.FeatureFactory;
import java.util.List;
static final Intent SEE_TIME_IN_APP_TEMPLATE = new Intent(Settings.ACTION_APP_USAGE_SETTINGS);
private final PackageManager mPackageManager;
-
+ private final ApplicationFeatureProvider mAppFeatureProvider;
private Intent mIntent;
private String mPackageName;
public TimeSpentInAppPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
mPackageManager = context.getPackageManager();
+ mAppFeatureProvider = FeatureFactory.getFactory(context)
+ .getApplicationFeatureProvider(context);
}
public void setPackageName(String packageName) {
}
}
+ @Override
+ public CharSequence getSummary() {
+ return mAppFeatureProvider.getTimeSpentInApp(mPackageName);
+ }
+
private boolean isSystemApp(ResolveInfo info) {
return info != null
&& info.activityInfo != null
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Test;
private ShadowPackageManager mPackageManager;
private TimeSpentInAppPreferenceController mController;
private Preference mPreference;
+ private FakeFeatureFactory mFeatureFactory;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mFeatureFactory = FakeFeatureFactory.setupForTest();
mContext = RuntimeEnvironment.application;
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
mController = new TimeSpentInAppPreferenceController(mContext, TEST_KEY);
assertThat(intent.getStringExtra(EXTRA_PACKAGE_NAME))
.isEqualTo(TEST_INTENT.getStringExtra(EXTRA_PACKAGE_NAME));
}
+
+ @Test
+ public void getSummary_shouldQueryAppFeatureProvider() {
+ mController.getSummary();
+
+ verify(mFeatureFactory.applicationFeatureProvider).getTimeSpentInApp(
+ nullable(String.class));
+ }
}