OSDN Git Service

Make android.settings.SETTINGS intent go into homepage.
authorFan Zhang <zhfan@google.com>
Fri, 26 Oct 2018 20:40:38 +0000 (13:40 -0700)
committerFan Zhang <zhfan@google.com>
Sun, 28 Oct 2018 22:59:24 +0000 (15:59 -0700)
Change-Id: Ib7453a79a473410c44bdcf06019446cedd34f837
Fixes: 117281845
Test: robotests

AndroidManifest.xml
src/com/android/settings/SettingsActivity.java
src/com/android/settings/homepage/SettingsHomepageActivity.java
tests/robotests/src/com/android/settings/SettingsActivityTest.java
tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java [new file with mode: 0644]

index bc832ef..1ffdba1 100644 (file)
         <uses-library android:name="org.apache.http.legacy" />
         <!-- Settings -->
 
-        <activity android:name="Settings"
+        <activity android:name="SettingsActivity"
                 android:label="@string/settings_label_launcher"
                 android:launchMode="singleTask">
-            <intent-filter android:priority="1">
-                <action android:name="android.settings.SETTINGS" />
-                <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
                 android:value="true" />
         </activity>
                   android:label="@string/settings_label_launcher"
                   android:theme="@style/Theme.Settings.Home"
                   android:launchMode="singleTask">
+            <intent-filter android:priority="1">
+                <action android:name="android.settings.SETTINGS" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+                       android:value="true" />
         </activity>
 
         <activity android:name=".network.telephony.MobileSettingsActivity"
 
         <receiver
             android:name=".slices.SliceBroadcastReceiver"
-            android:exported="false">
-        </receiver>
+            android:exported="false" />
 
         <receiver
             android:name=".slices.SliceRelayReceiver"
             android:permission="android.permission.MANAGE_SLICE_PERMISSIONS"
-            android:exported="true">
-
-        </receiver>
+            android:exported="true" />
 
         <!-- Couldn't be triggered from outside of settings. Statsd can trigger it because we send
              PendingIntent to it-->
index 8881fc2..8ed368c 100644 (file)
@@ -16,8 +16,6 @@
 
 package com.android.settings;
 
-import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO;
-
 import android.app.ActionBar;
 import android.app.ActivityManager;
 import android.content.BroadcastReceiver;
@@ -248,10 +246,8 @@ public class SettingsActivity extends SettingsBaseActivity
         // Getting Intent properties can only be done after the super.onCreate(...)
         final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
 
-        final ComponentName cn = intent.getComponent();
-        final String className = cn.getClassName();
-
-        mIsShowingDashboard = className.equals(Settings.class.getName());
+        mIsShowingDashboard = TextUtils.equals(
+                SettingsActivity.class.getName(), intent.getComponent().getClassName());
 
         // This is a "Sub Settings" when:
         // - this is a real SubSettings
index b3d1aa4..c10543d 100644 (file)
@@ -16,7 +16,6 @@
 
 package com.android.settings.homepage;
 
-import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.util.FeatureFlagUtils;
@@ -27,6 +26,7 @@ import androidx.fragment.app.FragmentManager;
 import androidx.fragment.app.FragmentTransaction;
 
 import com.android.settings.R;
+import com.android.settings.SettingsActivity;
 import com.android.settings.core.FeatureFlags;
 import com.android.settings.core.SettingsBaseActivity;
 import com.android.settings.homepage.contextualcards.ContextualCardsFragment;
@@ -38,9 +38,8 @@ public class SettingsHomepageActivity extends SettingsBaseActivity {
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        if (!isDynamicHomepageEnabled(this)) {
-            final Intent settings = new Intent();
-            settings.setAction("android.settings.SETTINGS");
+        if (!FeatureFlagUtils.isEnabled(this, FeatureFlags.DYNAMIC_HOMEPAGE)) {
+            final Intent settings = new Intent(this, SettingsActivity.class);
             startActivity(settings);
             finish();
             return;
@@ -56,10 +55,6 @@ public class SettingsHomepageActivity extends SettingsBaseActivity {
         showFragment(new TopLevelSettings(), R.id.main_content);
     }
 
-    public static boolean isDynamicHomepageEnabled(Context context) {
-        return FeatureFlagUtils.isEnabled(context, FeatureFlags.DYNAMIC_HOMEPAGE);
-    }
-
     private void showFragment(Fragment fragment, int id) {
         final FragmentManager fragmentManager = getSupportFragmentManager();
         final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
index 409512e..af25f48 100644 (file)
@@ -71,10 +71,9 @@ public class SettingsActivityTest {
     @Test
     public void onCreate_deviceNotProvisioned_shouldDisableSearch() {
         Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
-        final Intent intent = new Intent(mContext, Settings.class);
-        final SettingsActivity activity =
-                Robolectric.buildActivity(SettingsActivity.class, intent).create(
-                        Bundle.EMPTY).get();
+        final SettingsActivity activity = Robolectric.buildActivity(SettingsActivity.class)
+                .create(Bundle.EMPTY)
+                .get();
 
         assertThat(activity.findViewById(R.id.search_bar).getVisibility())
                 .isEqualTo(View.INVISIBLE);
@@ -83,10 +82,9 @@ public class SettingsActivityTest {
     @Test
     public void onCreate_deviceProvisioned_shouldEnableSearch() {
         Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
-        final Intent intent = new Intent(mContext, Settings.class);
-        final SettingsActivity activity =
-                Robolectric.buildActivity(SettingsActivity.class, intent).create(
-                        Bundle.EMPTY).get();
+        final SettingsActivity activity = Robolectric.buildActivity(SettingsActivity.class)
+                .create(Bundle.EMPTY)
+                .get();
 
         assertThat(activity.findViewById(R.id.search_bar).getVisibility()).isEqualTo(View.VISIBLE);
     }
diff --git a/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java b/tests/robotests/src/com/android/settings/homepage/SettingsHomepageActivityTest.java
new file mode 100644 (file)
index 0000000..f122819
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 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.homepage;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.util.FeatureFlagUtils;
+
+import com.android.settings.SettingsActivity;
+import com.android.settings.core.FeatureFlags;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
+import org.robolectric.shadows.ShadowActivity;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class SettingsHomepageActivityTest {
+
+    @Test
+    public void launch_featureFlagOff_shouldRedirectToSettingsActivity() {
+        FeatureFlagUtils.setEnabled(RuntimeEnvironment.application, FeatureFlags.DYNAMIC_HOMEPAGE,
+                false);
+
+        final ShadowActivity shadowActivity = Shadows.shadowOf(
+                Robolectric.setupActivity(SettingsHomepageActivity.class));
+        assertThat(shadowActivity.getNextStartedActivity().getComponent().getClassName())
+                .isEqualTo(SettingsActivity.class.getName());
+    }
+}