Integrate with SettingsIntelligence
Bug: 64691432 Test: robotests Change-Id: Idd20fd66f0289e0d0178bac02b1059c5554673f4
This commit is contained in:
@@ -72,6 +72,7 @@
|
|||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
<uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" />
|
<uses-permission android:name="android.permission.MANAGE_DEVICE_ADMINS" />
|
||||||
<uses-permission android:name="android.permission.READ_SEARCH_INDEXABLES" />
|
<uses-permission android:name="android.permission.READ_SEARCH_INDEXABLES" />
|
||||||
|
<uses-permission android:name="android.permission.BIND_SETTINGS_SUGGESTIONS_SERVICE" />
|
||||||
<uses-permission android:name="android.permission.OEM_UNLOCK_STATE" />
|
<uses-permission android:name="android.permission.OEM_UNLOCK_STATE" />
|
||||||
<uses-permission android:name="android.permission.MANAGE_USER_OEM_UNLOCK_STATE" />
|
<uses-permission android:name="android.permission.MANAGE_USER_OEM_UNLOCK_STATE" />
|
||||||
<uses-permission android:name="android.permission.OVERRIDE_WIFI_CONFIG" />
|
<uses-permission android:name="android.permission.OVERRIDE_WIFI_CONFIG" />
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
|||||||
import com.android.settings.dashboard.conditional.FocusRecyclerView.FocusListener;
|
import com.android.settings.dashboard.conditional.FocusRecyclerView.FocusListener;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionDismissController;
|
import com.android.settings.dashboard.suggestions.SuggestionDismissController;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||||
|
import com.android.settings.dashboard.suggestions.SuggestionControllerMixin;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionsChecks;
|
import com.android.settings.dashboard.suggestions.SuggestionsChecks;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.widget.ActionBarShadowController;
|
import com.android.settings.widget.ActionBarShadowController;
|
||||||
@@ -60,7 +61,6 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
private static final int MAX_WAIT_MILLIS = 700;
|
private static final int MAX_WAIT_MILLIS = 700;
|
||||||
private static final String TAG = "DashboardSummary";
|
private static final String TAG = "DashboardSummary";
|
||||||
|
|
||||||
|
|
||||||
private static final String EXTRA_SCROLL_POSITION = "scroll_position";
|
private static final String EXTRA_SCROLL_POSITION = "scroll_position";
|
||||||
|
|
||||||
private final Handler mHandler = new Handler();
|
private final Handler mHandler = new Handler();
|
||||||
@@ -72,6 +72,7 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
private SuggestionParser mSuggestionParser;
|
private SuggestionParser mSuggestionParser;
|
||||||
private LinearLayoutManager mLayoutManager;
|
private LinearLayoutManager mLayoutManager;
|
||||||
private SuggestionsChecks mSuggestionsChecks;
|
private SuggestionsChecks mSuggestionsChecks;
|
||||||
|
private SuggestionControllerMixin mSuggestionControllerMixin;
|
||||||
private DashboardFeatureProvider mDashboardFeatureProvider;
|
private DashboardFeatureProvider mDashboardFeatureProvider;
|
||||||
private SuggestionFeatureProvider mSuggestionFeatureProvider;
|
private SuggestionFeatureProvider mSuggestionFeatureProvider;
|
||||||
private boolean isOnCategoriesChangedCalled;
|
private boolean isOnCategoriesChangedCalled;
|
||||||
@@ -82,6 +83,12 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
return MetricsEvent.DASHBOARD_SUMMARY;
|
return MetricsEvent.DASHBOARD_SUMMARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
mSuggestionControllerMixin = new SuggestionControllerMixin(context, getLifecycle());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
@@ -196,7 +203,7 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
mDashboard.setHasFixedSize(true);
|
mDashboard.setHasFixedSize(true);
|
||||||
mDashboard.setListener(this);
|
mDashboard.setListener(this);
|
||||||
mAdapter = new DashboardAdapter(getContext(), bundle, mConditionManager.getConditions(),
|
mAdapter = new DashboardAdapter(getContext(), bundle, mConditionManager.getConditions(),
|
||||||
mSuggestionParser, this /* SuggestionDismissController.Callback */);
|
mSuggestionParser, this /* SuggestionDismissController.Callback */);
|
||||||
mDashboard.setAdapter(mAdapter);
|
mDashboard.setAdapter(mAdapter);
|
||||||
mDashboard.setItemAnimator(new DashboardItemAnimator());
|
mDashboard.setItemAnimator(new DashboardItemAnimator());
|
||||||
mSummaryLoader.setSummaryConsumer(mAdapter);
|
mSummaryLoader.setSummaryConsumer(mAdapter);
|
||||||
|
|||||||
@@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.dashboard.suggestions;
|
||||||
|
|
||||||
|
import android.annotation.Nullable;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.ServiceConnection;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.service.settings.suggestions.ISuggestionService;
|
||||||
|
import android.service.settings.suggestions.Suggestion;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||||
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages IPC communication to SettingsIntelligence for suggestion related services.
|
||||||
|
*/
|
||||||
|
public class SuggestionControllerMixin implements LifecycleObserver, OnStart, OnStop {
|
||||||
|
|
||||||
|
private static final String TAG = "SuggestionCtrlMixin";
|
||||||
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
|
private final Context mContext;
|
||||||
|
private final Intent mServiceIntent;
|
||||||
|
private final ServiceConnection mServiceConnection;
|
||||||
|
|
||||||
|
private ISuggestionService mRemoteService;
|
||||||
|
|
||||||
|
public SuggestionControllerMixin(Context context, Lifecycle lifecycle) {
|
||||||
|
mContext = context.getApplicationContext();
|
||||||
|
mServiceIntent = new Intent().setComponent(
|
||||||
|
new ComponentName(
|
||||||
|
"com.android.settings.intelligence",
|
||||||
|
"com.android.settings.intelligence.suggestions.SuggestionService"));
|
||||||
|
mServiceConnection = createServiceConnection();
|
||||||
|
if (lifecycle != null) {
|
||||||
|
lifecycle.addObserver(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
if (!isEnabled()) {
|
||||||
|
Log.w(TAG, "Feature not enabled, skipping");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mContext.bindServiceAsUser(mServiceIntent, mServiceConnection, Context.BIND_AUTO_CREATE,
|
||||||
|
android.os.Process.myUserHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
if (mRemoteService != null) {
|
||||||
|
mRemoteService = null;
|
||||||
|
mContext.unbindService(mServiceConnection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
// TODO: Set up feature flag
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get setting suggestions.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public List<Suggestion> getSuggestions() {
|
||||||
|
if (!isReady()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return mRemoteService.getSuggestions();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.w(TAG, "Error when calling getSuggestion()", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the manager is ready
|
||||||
|
*/
|
||||||
|
private boolean isReady() {
|
||||||
|
return mRemoteService != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void onServiceConnected() {
|
||||||
|
// TODO: Call API to get data from a loader instead of in current thread.
|
||||||
|
final List<Suggestion> data = getSuggestions();
|
||||||
|
Log.d(TAG, "data size " + (data == null ? 0 : data.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onServiceDisconnected() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link ServiceConnection} object to handle service connect/disconnect event.
|
||||||
|
*/
|
||||||
|
private ServiceConnection createServiceConnection() {
|
||||||
|
return new ServiceConnection() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "Service is connected");
|
||||||
|
}
|
||||||
|
mRemoteService = ISuggestionService.Stub.asInterface(service);
|
||||||
|
SuggestionControllerMixin.this.onServiceConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
|
mRemoteService = null;
|
||||||
|
SuggestionControllerMixin.this.onServiceDisconnected();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package android.service.settings.suggestions;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ISuggestionService {
|
||||||
|
List<Suggestion> getSuggestions();
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package android.service.settings.suggestions;
|
||||||
|
|
||||||
|
public class Suggestion {
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.dashboard.suggestions;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.service.settings.suggestions.ISuggestionService;
|
||||||
|
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class SuggestionControllerMixinTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Context mContext;
|
||||||
|
@Mock
|
||||||
|
private ISuggestionService mRemoteService;
|
||||||
|
private Lifecycle mLifecycle;
|
||||||
|
private SuggestionControllerMixin mMixin;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mLifecycle = new Lifecycle();
|
||||||
|
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void verifyIsEnabled() {
|
||||||
|
mMixin = new SuggestionControllerMixin(mContext, mLifecycle);
|
||||||
|
assertThat(mMixin.isEnabled()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onServiceConnected_shouldGetSuggestion() {
|
||||||
|
mMixin = new SuggestionControllerMixin(mContext, mLifecycle);
|
||||||
|
ReflectionHelpers.setField(mMixin, "mRemoteService", mRemoteService);
|
||||||
|
mMixin.onServiceConnected();
|
||||||
|
|
||||||
|
verify(mRemoteService).getSuggestions();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user