Merge "Don't start DPC with the FLAG_ACTIVITY_NEW_TASK flag" into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
3bc6b32b51
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.enterprise;
|
package com.android.settings.enterprise;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public interface EnterprisePrivacyFeatureProvider {
|
public interface EnterprisePrivacyFeatureProvider {
|
||||||
@@ -131,7 +133,7 @@ public interface EnterprisePrivacyFeatureProvider {
|
|||||||
* Launches the Device Owner or Profile Owner's activity that displays the "Your work policy
|
* Launches the Device Owner or Profile Owner's activity that displays the "Your work policy
|
||||||
* info" page. Returns {@code true} if the activity has indeed been launched.
|
* info" page. Returns {@code true} if the activity has indeed been launched.
|
||||||
*/
|
*/
|
||||||
boolean showWorkPolicyInfo();
|
boolean showWorkPolicyInfo(Context activityContext);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launches the parental controls settings page. Returns {@code true} if the activity has
|
* Launches the parental controls settings page. Returns {@code true} if the activity has
|
||||||
|
@@ -227,17 +227,17 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean showWorkPolicyInfo() {
|
public boolean showWorkPolicyInfo(Context activityContext) {
|
||||||
Intent intent = getWorkPolicyInfoIntentDO();
|
Intent intent = getWorkPolicyInfoIntentDO();
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
mContext.startActivity(intent);
|
activityContext.startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
intent = getWorkPolicyInfoIntentPO();
|
intent = getWorkPolicyInfoIntentPO();
|
||||||
final UserInfo userInfo = getManagedProfileUserInfo();
|
final UserInfo userInfo = getManagedProfileUserInfo();
|
||||||
if (intent != null && userInfo != null) {
|
if (intent != null && userInfo != null) {
|
||||||
mContext.startActivityAsUser(intent, userInfo.getUserHandle());
|
activityContext.startActivityAsUser(intent, userInfo.getUserHandle());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,8 +305,7 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
|
|||||||
// Only search for the required action in the Device Owner's package
|
// Only search for the required action in the Device Owner's package
|
||||||
final Intent intent =
|
final Intent intent =
|
||||||
new Intent(Settings.ACTION_SHOW_WORK_POLICY_INFO)
|
new Intent(Settings.ACTION_SHOW_WORK_POLICY_INFO)
|
||||||
.setPackage(ownerComponent.getPackageName())
|
.setPackage(ownerComponent.getPackageName());
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
final List<ResolveInfo> activities = mPm.queryIntentActivities(intent, 0);
|
final List<ResolveInfo> activities = mPm.queryIntentActivities(intent, 0);
|
||||||
if (activities.size() != 0) {
|
if (activities.size() != 0) {
|
||||||
return intent;
|
return intent;
|
||||||
@@ -329,8 +328,7 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
|
|||||||
// Only search for the required action in the Profile Owner's package
|
// Only search for the required action in the Profile Owner's package
|
||||||
final Intent intent =
|
final Intent intent =
|
||||||
new Intent(Settings.ACTION_SHOW_WORK_POLICY_INFO)
|
new Intent(Settings.ACTION_SHOW_WORK_POLICY_INFO)
|
||||||
.setPackage(ownerComponent.getPackageName())
|
.setPackage(ownerComponent.getPackageName());
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
final List<ResolveInfo> activities = mPm.queryIntentActivitiesAsUser(intent, 0, userId);
|
final List<ResolveInfo> activities = mPm.queryIntentActivitiesAsUser(intent, 0, userId);
|
||||||
if (activities.size() != 0) {
|
if (activities.size() != 0) {
|
||||||
return intent;
|
return intent;
|
||||||
|
@@ -45,7 +45,7 @@ public class WorkPolicyInfoPreferenceController extends BasePreferenceController
|
|||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
if (TextUtils.equals(getPreferenceKey(), preference.getKey())) {
|
if (TextUtils.equals(getPreferenceKey(), preference.getKey())) {
|
||||||
mEnterpriseProvider.showWorkPolicyInfo();
|
mEnterpriseProvider.showWorkPolicyInfo(preference.getContext());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@@ -356,7 +356,7 @@ public class EnterprisePrivacyFeatureProviderImplTest {
|
|||||||
addWorkPolicyInfoIntent(mOwner.getPackageName(), true, false);
|
addWorkPolicyInfoIntent(mOwner.getPackageName(), true, false);
|
||||||
assertThat(mProvider.hasWorkPolicyInfo()).isFalse();
|
assertThat(mProvider.hasWorkPolicyInfo()).isFalse();
|
||||||
|
|
||||||
assertThat(mProvider.showWorkPolicyInfo()).isFalse();
|
assertThat(mProvider.showWorkPolicyInfo(mContext)).isFalse();
|
||||||
verify(mContext, never()).startActivity(any());
|
verify(mContext, never()).startActivity(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,12 +365,12 @@ public class EnterprisePrivacyFeatureProviderImplTest {
|
|||||||
// If the intent is not resolved, then there's no info to show for DO
|
// If the intent is not resolved, then there's no info to show for DO
|
||||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(mOwner);
|
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(mOwner);
|
||||||
assertThat(mProvider.hasWorkPolicyInfo()).isFalse();
|
assertThat(mProvider.hasWorkPolicyInfo()).isFalse();
|
||||||
assertThat(mProvider.showWorkPolicyInfo()).isFalse();
|
assertThat(mProvider.showWorkPolicyInfo(mContext)).isFalse();
|
||||||
|
|
||||||
// If the intent is resolved, then we can use it to launch the activity
|
// If the intent is resolved, then we can use it to launch the activity
|
||||||
Intent intent = addWorkPolicyInfoIntent(mOwner.getPackageName(), true, false);
|
Intent intent = addWorkPolicyInfoIntent(mOwner.getPackageName(), true, false);
|
||||||
assertThat(mProvider.hasWorkPolicyInfo()).isTrue();
|
assertThat(mProvider.hasWorkPolicyInfo()).isTrue();
|
||||||
assertThat(mProvider.showWorkPolicyInfo()).isTrue();
|
assertThat(mProvider.showWorkPolicyInfo(mContext)).isTrue();
|
||||||
verify(mContext).startActivity(intentEquals(intent));
|
verify(mContext).startActivity(intentEquals(intent));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,12 +382,12 @@ public class EnterprisePrivacyFeatureProviderImplTest {
|
|||||||
|
|
||||||
// If the intent is not resolved, then there's no info to show for PO
|
// If the intent is not resolved, then there's no info to show for PO
|
||||||
assertThat(mProvider.hasWorkPolicyInfo()).isFalse();
|
assertThat(mProvider.hasWorkPolicyInfo()).isFalse();
|
||||||
assertThat(mProvider.showWorkPolicyInfo()).isFalse();
|
assertThat(mProvider.showWorkPolicyInfo(mContext)).isFalse();
|
||||||
|
|
||||||
// If the intent is resolved, then we can use it to launch the activity in managed profile
|
// If the intent is resolved, then we can use it to launch the activity in managed profile
|
||||||
Intent intent = addWorkPolicyInfoIntent(mOwner.getPackageName(), false, true);
|
Intent intent = addWorkPolicyInfoIntent(mOwner.getPackageName(), false, true);
|
||||||
assertThat(mProvider.hasWorkPolicyInfo()).isTrue();
|
assertThat(mProvider.hasWorkPolicyInfo()).isTrue();
|
||||||
assertThat(mProvider.showWorkPolicyInfo()).isTrue();
|
assertThat(mProvider.showWorkPolicyInfo(mContext)).isTrue();
|
||||||
verify(mContext)
|
verify(mContext)
|
||||||
.startActivityAsUser(
|
.startActivityAsUser(
|
||||||
intentEquals(intent),
|
intentEquals(intent),
|
||||||
@@ -402,12 +402,12 @@ public class EnterprisePrivacyFeatureProviderImplTest {
|
|||||||
|
|
||||||
// If the intent is not resolved, then there's no info to show for COMP
|
// If the intent is not resolved, then there's no info to show for COMP
|
||||||
assertThat(mProvider.hasWorkPolicyInfo()).isFalse();
|
assertThat(mProvider.hasWorkPolicyInfo()).isFalse();
|
||||||
assertThat(mProvider.showWorkPolicyInfo()).isFalse();
|
assertThat(mProvider.showWorkPolicyInfo(mContext)).isFalse();
|
||||||
|
|
||||||
// If the intent is resolved, then we can use it to launch the activity for device owner
|
// If the intent is resolved, then we can use it to launch the activity for device owner
|
||||||
Intent intent = addWorkPolicyInfoIntent(mOwner.getPackageName(), true, true);
|
Intent intent = addWorkPolicyInfoIntent(mOwner.getPackageName(), true, true);
|
||||||
assertThat(mProvider.hasWorkPolicyInfo()).isTrue();
|
assertThat(mProvider.hasWorkPolicyInfo()).isTrue();
|
||||||
assertThat(mProvider.showWorkPolicyInfo()).isTrue();
|
assertThat(mProvider.showWorkPolicyInfo(mContext)).isTrue();
|
||||||
verify(mContext).startActivity(intentEquals(intent));
|
verify(mContext).startActivity(intentEquals(intent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -80,7 +80,7 @@ public class WorkPolicyInfoPreferenceControllerTest {
|
|||||||
|
|
||||||
final Preference pref = new Preference(mContext);
|
final Preference pref = new Preference(mContext);
|
||||||
assertThat(controller.handlePreferenceTreeClick(pref)).isFalse();
|
assertThat(controller.handlePreferenceTreeClick(pref)).isFalse();
|
||||||
verify(mEnterpriseProvider, never()).showWorkPolicyInfo();
|
verify(mEnterpriseProvider, never()).showWorkPolicyInfo(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -92,6 +92,6 @@ public class WorkPolicyInfoPreferenceControllerTest {
|
|||||||
final Preference pref = new Preference(mContext);
|
final Preference pref = new Preference(mContext);
|
||||||
pref.setKey(controller.getPreferenceKey());
|
pref.setKey(controller.getPreferenceKey());
|
||||||
assertThat(controller.handlePreferenceTreeClick(pref)).isTrue();
|
assertThat(controller.handlePreferenceTreeClick(pref)).isTrue();
|
||||||
verify(mEnterpriseProvider).showWorkPolicyInfo();
|
verify(mEnterpriseProvider).showWorkPolicyInfo(mContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user