Add a metadata to control whether an external intent should be opened in

the personal profile when in a managed profile.

This change introduces the com.android.settings.profile metadata with possible values "primary_profile_only" and "all_profiles" (the default value when not specified). If an application declares this metadata with a value of "primary_profile_only", in a work profile the ProfileSelectDialog is never shown and the application is opened straight in the personal profile. If an application specifies a value of "all_profiles" or does not specify anything, the ProfileSelectDialog is shown to the user.

Test: atest frameworks/base/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileTest.java
Bug: 79868199
Change-Id: I82860307e5745f4c7044980225114efcdcf0c90f
This commit is contained in:
arangelov
2018-05-30 18:24:23 +01:00
committed by Antoan Angelov
parent 43dcdf898c
commit 24eec2f6eb
3 changed files with 88 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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();
}
}