Merge "Add a metadata to control whether an external intent should be opened in the personal profile when in a managed profile."
This commit is contained in:
committed by
Android (Google) Code Review
commit
6d5bdf293d
@@ -16,6 +16,10 @@
|
||||
|
||||
package com.android.settingslib.drawer;
|
||||
|
||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE;
|
||||
import static com.android.settingslib.drawer.TileUtils.PROFILE_ALL;
|
||||
import static com.android.settingslib.drawer.TileUtils.PROFILE_PRIMARY;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
@@ -169,4 +173,11 @@ public class Tile implements Parcelable {
|
||||
return new Tile[size];
|
||||
}
|
||||
};
|
||||
|
||||
public boolean isPrimaryProfileOnly() {
|
||||
String profile = metaData != null ?
|
||||
metaData.getString(META_DATA_KEY_PROFILE) : PROFILE_ALL;
|
||||
profile = (profile != null ? profile : PROFILE_ALL);
|
||||
return TextUtils.equals(profile, PROFILE_PRIMARY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -168,6 +169,34 @@ public class TileUtils {
|
||||
|
||||
public static final String SETTING_PKG = "com.android.settings";
|
||||
|
||||
/**
|
||||
* Value for {@link #META_DATA_KEY_PROFILE}. When the device has a managed profile,
|
||||
* the app will always be run in the primary profile.
|
||||
*
|
||||
* @see #META_DATA_KEY_PROFILE
|
||||
*/
|
||||
public static final String PROFILE_PRIMARY = "primary_profile_only";
|
||||
|
||||
/**
|
||||
* Value for {@link #META_DATA_KEY_PROFILE}. When the device has a managed profile, the user
|
||||
* will be presented with a dialog to choose the profile the app will be run in.
|
||||
*
|
||||
* @see #META_DATA_KEY_PROFILE
|
||||
*/
|
||||
public static final String PROFILE_ALL = "all_profiles";
|
||||
|
||||
/**
|
||||
* Name of the meta-data item that should be set in the AndroidManifest.xml
|
||||
* to specify the profile in which the app should be run when the device has a managed profile.
|
||||
* The default value is {@link #PROFILE_ALL} which means the user will be presented with a
|
||||
* dialog to choose the profile. If set to {@link #PROFILE_PRIMARY} the app will always be
|
||||
* run in the primary profile.
|
||||
*
|
||||
* @see #PROFILE_PRIMARY
|
||||
* @see #PROFILE_ALL
|
||||
*/
|
||||
public static final String META_DATA_KEY_PROFILE = "com.android.settings.profile";
|
||||
|
||||
/**
|
||||
* Build a list of DashboardCategory. Each category must be defined in manifest.
|
||||
* eg: .Settings$DeviceSettings
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.android.settingslib.drawer;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE;
|
||||
import static com.android.settingslib.drawer.TileUtils.PROFILE_ALL;
|
||||
import static com.android.settingslib.drawer.TileUtils.PROFILE_PRIMARY;
|
||||
|
||||
import android.os.Bundle;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.junit.Test;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class TileTest {
|
||||
|
||||
private Tile mTile;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mTile = new Tile();
|
||||
mTile.metaData = new Bundle();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPrimaryProfileOnly_profilePrimary_shouldReturnTrue() {
|
||||
mTile.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_PRIMARY);
|
||||
assertThat(mTile.isPrimaryProfileOnly()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPrimaryProfileOnly_profileAll_shouldReturnFalse() {
|
||||
mTile.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_ALL);
|
||||
assertThat(mTile.isPrimaryProfileOnly()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPrimaryProfileOnly_noExplicitValue_shouldReturnFalse() {
|
||||
assertThat(mTile.isPrimaryProfileOnly()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPrimaryProfileOnly_nullMetadata_shouldReturnFalse() {
|
||||
mTile.metaData = null;
|
||||
assertThat(mTile.isPrimaryProfileOnly()).isFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user