Avoid 2-pane deep link before gone through Setup Wizard

To improve security.

Fix: 238391432
Test: manual
      Flash ROM and check 2-pane bebavior
Change-Id: If96c645319d9df45930644fd438cf479462685b0
This commit is contained in:
Arc Wang
2022-07-08 15:46:40 +08:00
parent b1cb90f7f1
commit be2ea9eb39
3 changed files with 75 additions and 18 deletions

View File

@@ -17,11 +17,19 @@
package com.android.settings; package com.android.settings;
import android.app.Application; import android.app.Application;
import android.database.ContentObserver;
import android.net.Uri;
import android.provider.Settings;
import android.util.FeatureFlagUtils;
import androidx.window.embedding.SplitController;
import com.android.settings.activityembedding.ActivityEmbeddingRulesController; import com.android.settings.activityembedding.ActivityEmbeddingRulesController;
import com.android.settings.homepage.SettingsHomepageActivity; import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settingslib.applications.AppIconCacheManager; import com.android.settingslib.applications.AppIconCacheManager;
import com.google.android.setupcompat.util.WizardManagerHelper;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
/** Settings application which sets up activity embedding rules for the large screen device. */ /** Settings application which sets up activity embedding rules for the large screen device. */
@@ -33,9 +41,14 @@ public class SettingsApplication extends Application {
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
final ActivityEmbeddingRulesController controller = if (FeatureFlagUtils.isEnabled(this, FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN)
new ActivityEmbeddingRulesController(this); && SplitController.getInstance().isSplitSupported()) {
controller.initRules(); if (WizardManagerHelper.isUserSetupComplete(this)) {
new ActivityEmbeddingRulesController(this).initRules();
} else {
new DeviceProvisionedObserver().registerContentObserver();
}
}
} }
public void setHomeActivity(SettingsHomepageActivity homeActivity) { public void setHomeActivity(SettingsHomepageActivity homeActivity) {
@@ -51,4 +64,30 @@ public class SettingsApplication extends Application {
super.onLowMemory(); super.onLowMemory();
AppIconCacheManager.getInstance().release(); AppIconCacheManager.getInstance().release();
} }
private class DeviceProvisionedObserver extends ContentObserver {
private final Uri mDeviceProvisionedUri = Settings.Secure.getUriFor(
Settings.Secure.USER_SETUP_COMPLETE);
DeviceProvisionedObserver() {
super(null /* handler */);
}
@Override
public void onChange(boolean selfChange, Uri uri, int flags) {
if (!mDeviceProvisionedUri.equals(uri)) {
return;
}
SettingsApplication.this.getContentResolver().unregisterContentObserver(this);
new ActivityEmbeddingRulesController(SettingsApplication.this).initRules();
}
public void registerContentObserver() {
SettingsApplication.this.getContentResolver().registerContentObserver(
mDeviceProvisionedUri,
false /* notifyForDescendants */,
this);
}
}
} }

View File

@@ -27,6 +27,8 @@ import androidx.window.embedding.SplitController;
import com.android.settings.R; import com.android.settings.R;
import com.google.android.setupcompat.util.WizardManagerHelper;
/** An util class collecting all common methods for the embedding activity features. */ /** An util class collecting all common methods for the embedding activity features. */
public class ActivityEmbeddingUtils { public class ActivityEmbeddingUtils {
// The smallest value of current width of the window when the split should be used. // The smallest value of current width of the window when the split should be used.
@@ -65,14 +67,16 @@ public class ActivityEmbeddingUtils {
/** Whether to support embedding activity feature. */ /** Whether to support embedding activity feature. */
public static boolean isEmbeddingActivityEnabled(Context context) { public static boolean isEmbeddingActivityEnabled(Context context) {
final boolean isFlagEnabled = FeatureFlagUtils.isEnabled(context, boolean isFlagEnabled = FeatureFlagUtils.isEnabled(context,
FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN); FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN);
final boolean isSplitSupported = SplitController.getInstance().isSplitSupported(); boolean isSplitSupported = SplitController.getInstance().isSplitSupported();
boolean isUserSetupComplete = WizardManagerHelper.isUserSetupComplete(context);
Log.d(TAG, "isFlagEnabled = " + isFlagEnabled); Log.d(TAG, "isFlagEnabled = " + isFlagEnabled);
Log.d(TAG, "isSplitSupported = " + isSplitSupported); Log.d(TAG, "isSplitSupported = " + isSplitSupported);
Log.d(TAG, "isUserSetupComplete = " + isUserSetupComplete);
return isFlagEnabled && isSplitSupported; return isFlagEnabled && isSplitSupported && isUserSetupComplete;
} }
/** Whether to show the regular or simplified homepage layout. */ /** Whether to show the regular or simplified homepage layout. */

View File

@@ -68,6 +68,8 @@ import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.Utils; import com.android.settingslib.Utils;
import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin; import com.android.settingslib.core.lifecycle.HideNonSystemOverlayMixin;
import com.google.android.setupcompat.util.WizardManagerHelper;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Set; import java.util.Set;
@@ -219,7 +221,9 @@ public class SettingsHomepageActivity extends FragmentActivity implements
}, R.id.main_content); }, R.id.main_content);
// Launch the intent from deep link for large screen devices. // Launch the intent from deep link for large screen devices.
launchDeepLinkIntentToRight(); if (shouldLaunchDeepLinkIntentToRight()) {
launchDeepLinkIntentToRight();
}
updateHomepagePaddings(); updateHomepagePaddings();
updateSplitLayout(); updateSplitLayout();
} }
@@ -242,7 +246,9 @@ public class SettingsHomepageActivity extends FragmentActivity implements
return; return;
} }
// Launch the intent from deep link for large screen devices. // Launch the intent from deep link for large screen devices.
launchDeepLinkIntentToRight(); if (shouldLaunchDeepLinkIntentToRight()) {
launchDeepLinkIntentToRight();
}
} }
@Override @Override
@@ -390,17 +396,18 @@ public class SettingsHomepageActivity extends FragmentActivity implements
return showFragment; return showFragment;
} }
private boolean shouldLaunchDeepLinkIntentToRight() {
if (!FeatureFlagUtils.isEnabled(this, FeatureFlagUtils.SETTINGS_SUPPORT_LARGE_SCREEN)
|| !SplitController.getInstance().isSplitSupported()) {
return false;
}
Intent intent = getIntent();
return intent != null && TextUtils.equals(intent.getAction(),
ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY);
}
private void launchDeepLinkIntentToRight() { private void launchDeepLinkIntentToRight() {
if (!mIsEmbeddingActivityEnabled) {
return;
}
final Intent intent = getIntent();
if (intent == null || !TextUtils.equals(intent.getAction(),
ACTION_SETTINGS_EMBED_DEEP_LINK_ACTIVITY)) {
return;
}
if (!(this instanceof DeepLinkHomepageActivity if (!(this instanceof DeepLinkHomepageActivity
|| this instanceof DeepLinkHomepageActivityInternal)) { || this instanceof DeepLinkHomepageActivityInternal)) {
Log.e(TAG, "Not a deep link component"); Log.e(TAG, "Not a deep link component");
@@ -408,6 +415,13 @@ public class SettingsHomepageActivity extends FragmentActivity implements
return; return;
} }
if (!WizardManagerHelper.isUserSetupComplete(this)) {
Log.e(TAG, "Cancel deep link before SUW completed");
finish();
return;
}
final Intent intent = getIntent();
final String intentUriString = intent.getStringExtra( final String intentUriString = intent.getStringExtra(
EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_INTENT_URI); EXTRA_SETTINGS_EMBEDDED_DEEP_LINK_INTENT_URI);
if (TextUtils.isEmpty(intentUriString)) { if (TextUtils.isEmpty(intentUriString)) {