OSDN Git Service

Pass component name into SuggestionFeatureProvider
authorMaurice Lam <yukl@google.com>
Thu, 25 May 2017 00:51:06 +0000 (17:51 -0700)
committerMaurice Lam <yukl@google.com>
Tue, 30 May 2017 20:07:51 +0000 (13:07 -0700)
So that the provider can be used for more than one suggestion.

Test: Robolectric test for implementation of the provider
Bug: 62039057
Change-Id: Ibea41ea6d98e67c55ec157556675e854f3ea31c4

src/com/android/settings/dashboard/suggestions/SuggestionFeatureProvider.java
src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java
src/com/android/settings/dashboard/suggestions/SuggestionsChecks.java

index a5a6d7a..7cb3753 100644 (file)
@@ -16,7 +16,9 @@
 
 package com.android.settings.dashboard.suggestions;
 
+import android.content.ComponentName;
 import android.content.Context;
+import android.support.annotation.NonNull;
 
 import com.android.settingslib.drawer.Tile;
 import com.android.settingslib.suggestions.SuggestionParser;
@@ -31,11 +33,11 @@ public interface SuggestionFeatureProvider {
      */
     boolean isSmartSuggestionEnabled(Context context);
 
-    /** Return true if className is the name of a class of one of your newly added suggestion. */
-    boolean isPresent(String className);
+    /** Return true if {@code suggestion} is managed by this provider. */
+    boolean isPresent(@NonNull ComponentName suggestion);
 
     /** Return true if the suggestion has already been completed and does not need to be shown */
-    boolean isSuggestionCompleted(Context context);
+    boolean isSuggestionCompleted(Context context, @NonNull ComponentName suggestion);
 
     /**
      * Ranks the list of suggestions in place.
index 0a14232..a2289e1 100644 (file)
 
 package com.android.settings.dashboard.suggestions;
 
+import android.content.ComponentName;
 import android.content.Context;
 import android.content.pm.PackageManager;
+import android.support.annotation.NonNull;
 import android.util.Log;
 
 import com.android.internal.logging.nano.MetricsProto;
@@ -42,12 +44,12 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
     }
 
     @Override
-    public boolean isPresent(String className) {
+    public boolean isPresent(@NonNull ComponentName component) {
         return false;
     }
 
     @Override
-    public boolean isSuggestionCompleted(Context context) {
+    public boolean isSuggestionCompleted(Context context, @NonNull ComponentName component) {
         return false;
     }
 
index f4a11e9..ab845a3 100644 (file)
@@ -21,6 +21,7 @@ import android.app.KeyguardManager;
 import android.app.NotificationManager;
 import android.app.WallpaperManager;
 import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
 import android.content.Context;
 import android.hardware.fingerprint.FingerprintManager;
 import android.provider.Settings;
@@ -56,7 +57,8 @@ public class SuggestionsChecks {
     }
 
     public boolean isSuggestionComplete(Tile suggestion) {
-        String className = suggestion.intent.getComponent().getClassName();
+        ComponentName component = suggestion.intent.getComponent();
+        String className = component.getClassName();
         if (className.equals(ZenModeAutomationSuggestionActivity.class.getName())) {
             return hasEnabledZenAutoRules();
         } else if (className.equals(WallpaperSuggestionActivity.class.getName())) {
@@ -79,8 +81,8 @@ public class SuggestionsChecks {
 
         SuggestionFeatureProvider provider =
                 FeatureFactory.getFactory(mContext).getSuggestionFeatureProvider(mContext);
-        if (provider != null && provider.isPresent(className)) {
-            return provider.isSuggestionCompleted(mContext);
+        if (provider != null && provider.isPresent(component)) {
+            return provider.isSuggestionCompleted(mContext, component);
         }
 
         return false;